GDI+ Problem!
-
I use GDI+ in my project under windows Vista/7 without any problems. But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception. I found that pBmp1 is NULL under the windows XP: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); ASSERT(pBmp1->GetLastStatus() == Ok); How can i Correct it? Best, MJM
-
I use GDI+ in my project under windows Vista/7 without any problems. But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception. I found that pBmp1 is NULL under the windows XP: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); ASSERT(pBmp1->GetLastStatus() == Ok); How can i Correct it? Best, MJM
mostafa_pasha wrote:
But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
Which is it? Does it fail to compile, or does it crash when you run it? If it fails to compile, what is the specific error message?
L u n a t i c F r i n g e
-
I use GDI+ in my project under windows Vista/7 without any problems. But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception. I found that pBmp1 is NULL under the windows XP: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); ASSERT(pBmp1->GetLastStatus() == Ok); How can i Correct it? Best, MJM
First, you need to be more clear about the error. Is it a runtime error, or compile time? What is the error?
-
First, you need to be more clear about the error. Is it a runtime error, or compile time? What is the error?
-
:-O
-
mostafa_pasha wrote:
But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
Which is it? Does it fail to compile, or does it crash when you run it? If it fails to compile, what is the specific error message?
L u n a t i c F r i n g e
first, it is runtime error! I said that when i debug the code under windows XP! (it means i can compile and run the program), pBmp1 which is the GDI+ object is NULL!!! but under windows vista/7, All is OK. My program is MDI. My project setting is USED MFC LIBRARY AS SHARED DLL! Does it depend on the updates for windows XP or Not? Best, MJM
-
first, it is runtime error! I said that when i debug the code under windows XP! (it means i can compile and run the program), pBmp1 which is the GDI+ object is NULL!!! but under windows vista/7, All is OK. My program is MDI. My project setting is USED MFC LIBRARY AS SHARED DLL! Does it depend on the updates for windows XP or Not? Best, MJM
mostafa_pasha wrote:
I said that when i debug the code under windows XP! (it means i can compile and run the program), pBmp1 which is the GDI+ object is NULL!!!
Noooo, you said this:
mostafa_pasha wrote:
But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception.
There is a difference, although I take it from the second post that the first was incorrect; that is, you say now that you CAN compile under XP.
mostafa_pasha wrote:
My program is MDI.
Probably irrelevant.
mostafa_pasha wrote:
My project setting is USED MFC LIBRARY AS SHARED DLL!
Again, probably irrelevant, although you could build the project with MFC linked as a static library to eliminate the possibility.
mostafa_pasha wrote:
Does it depend on the updates for windows XP or Not?
Perhaps; I don't know if the GDI+ runtime was affected by any updates, but it's always advisable to make sure your system is fully up to date. If it isn't, that's a good place to start, although I wouldn't hold out TOO much hope. Have you tried using LoadImage instead of LoadBitmap? LoadImage will allow you to specify that you want the image loaded as a DIBSection, which is device independent. (Are your display settings different in XP? LoadBitmap tries to load the image in a display-compatible format; LoadImage might get you around any problem associated with this.)
L u n a t i c F r i n g e
-
I use GDI+ in my project under windows Vista/7 without any problems. But when i try to compile the code or run the code under windows XP, the program crashes/ the compiler throw an exception. I found that pBmp1 is NULL under the windows XP: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); ASSERT(pBmp1->GetLastStatus() == Ok); How can i Correct it? Best, MJM
I think you can debug into Bitmap::FromHBITMAP() function and see what is going wrong.
-
I think you can debug into Bitmap::FromHBITMAP() function and see what is going wrong.
return NULL It means can not initilaize Bitmap!!! Does it mean it can not initialize the GDI+? inline Bitmap* Bitmap::FromHBITMAP( IN HBITMAP hbm, IN HPALETTE hpal ) { return new Bitmap(hbm, hpal); }
-
return NULL It means can not initilaize Bitmap!!! Does it mean it can not initialize the GDI+? inline Bitmap* Bitmap::FromHBITMAP( IN HBITMAP hbm, IN HPALETTE hpal ) { return new Bitmap(hbm, hpal); }
mostafa_pasha wrote:
return NULL
If it returns NULL then it means the function failed and you should use
GetLastError()
to find out why. Incidentally the code above is somewhat different from the code in your original message. Try to use exactly the same code and trace through it with the debugger noting all the values of your variables.txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
return NULL It means can not initilaize Bitmap!!! Does it mean it can not initialize the GDI+? inline Bitmap* Bitmap::FromHBITMAP( IN HBITMAP hbm, IN HPALETTE hpal ) { return new Bitmap(hbm, hpal); }
You can actually debug further into Bitmap() constructor to see what is happening there. I hope you have already initialized GDI+ by calling GdiplusStartup() function and checking it's return value.
-
mostafa_pasha wrote:
return NULL
If it returns NULL then it means the function failed and you should use
GetLastError()
to find out why. Incidentally the code above is somewhat different from the code in your original message. Try to use exactly the same code and trace through it with the debugger noting all the values of your variables.txtspeak is the realm of 9 year old children, not developers. Christian Graus
the code is here: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); hbmp1 0xb8051055 pBmp1 0x00000000 in LoadBitmap function: inline Bitmap* Bitmap::FromHBITMAP( IN HBITMAP hbm, IN HPALETTE hpal ) { return new Bitmap(hbm, hpal); } void* (operator new)(size_t in_size) { return DllExports::GdipAlloc(in_size); } in_size = 16 return 0x000000000 Best, MJM
-
the code is here: HBITMAP hbmp1 = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)); ASSERT(hbmp1!=NULL); Bitmap* pBmp1 = Bitmap::FromHBITMAP(hbmp1,NULL); hbmp1 0xb8051055 pBmp1 0x00000000 in LoadBitmap function: inline Bitmap* Bitmap::FromHBITMAP( IN HBITMAP hbm, IN HPALETTE hpal ) { return new Bitmap(hbm, hpal); } void* (operator new)(size_t in_size) { return DllExports::GdipAlloc(in_size); } in_size = 16 return 0x000000000 Best, MJM
In your call to
Bitmap::FromHBITMAP(hbmp1,NULL);
you have given NULL as the second parameter; are you sure this is correct? The documentation here[^] says this must be the handle to a GDI palette. You should also useGetLastError()
as I suggested previously to check why the call failed.txtspeak is the realm of 9 year old children, not developers. Christian Graus