If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: memcpy error in MFC

You do not provide a compilable project, and from your description it's not clear what kind of error you get. Is it compile time error? run time error? If run time, did you try to debug your code and inspect the parameters that were passed to memcpy?

As for the WM_PAIN handler design, it seems you totally ignored all my comments provided in the other thread's post. So please be aware that you keep going wrong way.

Please, do not put more than one statement in the same line! Code written in such a manner (two or three statements per line) is very hard to read, very hard to debug and very hard to maintain!
Besides, why do you insert an empty line after each line with code? It only makes sense if you separate some logical parts or blocks of your code, but there is no any in your code snippet!

The "&" used above is not the reference operator. That is the address-of operator, and has nothing to do with references. The code is perfectly valid. There is nothing wrong syntactically with it.

What is wrong is that the pointer value returned by operator new[] is stored in p, but then it is thrown away by assigning another address to "p" immediately afterwards. That is exactly what your code you say is "resolved" was doing, so nothing has been "resolved".

All you did in your new code was to move the memory corruption bug somewhere else. These lines did absolutely nothing except cause a memory leak, and worse, it masked the underlying problem:

Do you see the similarity between the code above, and the simple example I posted?

What I suggest is that you get rid of your "solution", bring back the old code that caused the problem, and fix the program correctly without throwing random lines of code that just masks the bug (i.e. changes the executable image so that the memory bug is hidden, but not fixed).

Unlike other computer languages, it is very easy to think that a problem is "resolved" in C++ by writing random lines of code and seeing the problem seemingly disappear without reason. But that is not a solution -- the only coded solutions in C++ are ones that can be explained coherently as to why the new code solves the problem.

Re: memcpy error in MFC

Originally Posted by Paul McKenzie

Unlike other computer languages, it is very easy to think that a problem is "resolved" in C++ by writing random lines of code and seeing the problem seemingly disappear without reason. But that is not a solution -- the only coded solutions in C++ are ones that can be explained coherently as to why the new code solves the problem.

True, so true. When trying to find a problem in a program the one thing I hate above all others is to add an innocuous print statement and either find the problem 'has gone away' or a different problem appears. This invariably means a memory corruption problem somwhere and a late night debugging session! Just because a c++ program seems to work on your computer doesn't mean that it will work correctly on another computer - or even on yours the next day! That's why c++ programs need to be carefully designed, coded, tested and thoroughly debugged to make sure they are robust.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: memcpy error in MFC

Originally Posted by 2kaud

That's why c++ programs need to be carefully designed, coded, tested and thoroughly debugged to make sure they are robust.

You make it sound like C++ is necessarily so.
You can just as well adopt methodology and use/by/develop libraries that will let you develop C++ code with the same ease as other languages while still allowing you to go "out of the confines of the box" if such is needed.

Yes, C++ allows you to write "messy" code, that doesn't mean it's smart to do so

Re: memcpy error in MFC

Originally Posted by OReubens

You can just as well adopt methodology and use/by/develop libraries that will let you develop C++ code with the same ease as other languages while still allowing you to go "out of the confines of the box" if such is needed.

Yes, C++ allows you to write "messy" code, that doesn't mean it's smart to do so

Agreed. But IMO this comes back to a recurring theme in these forums - correct teaching of c++.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.