I find my mistake and cleared. Its a exceed buffer size problem.
Code:
BYTE * src = new BYTE[bytes];
src = (BYTE*)bm1.bmBits;
Do you see what's wrong with those two lines? Forget about bitmap data for a moment -- on a C++ level, do you see the issue with those two lines above?
The new[] returns a pointer value. Then on the second line, you just throw it away and replace that value with another. How are you going to deallocate the memory if you throw away the original value?
Your code is no different than just doing this:
Code:
src = (BYTE*)bm1.bmBits;
but it's worse now that you've introduced a memory leak.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; June 23rd, 2013 at 11:31 PM.
I'm in beginner stage. If i'm doing any mistake, please take me to a right path at all time.
Code:
int main()
{
int x = 0;
int *p = new int [10];
p = &x;
}
This is basically what your bit of code I pointed out is doing. You tell us -- do you see what's wrong with those three lines of code above? It gets worse if you then do this:
Code:
int main()
{
int x = 0;
int *p = new int [10];
p = &x;
delete [] p;
}
What is wrong with the lines above? If you don't know, then you have a much larger issue than bitmap handling -- you need to know how to use the C++ language properly.
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!
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.
So what's the result of Arjay's request from post #2?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
* 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.