Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ Problem!

GDI+ Problem!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionwinformshelp
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mostafa_pasha
    wrote on last edited by
    #1

    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

    L Richard Andrew x64R K 3 Replies Last reply
    0
    • M mostafa_pasha

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M mostafa_pasha

        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

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #3

        First, you need to be more clear about the error. Is it a runtime error, or compile time? What is the error?

        L 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          First, you need to be more clear about the error. Is it a runtime error, or compile time? What is the error?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hey, what is this? You reading over my shoulder? :laugh:

          L u n a t i c F r i n g e

          Richard Andrew x64R 1 Reply Last reply
          0
          • L Lost User

            Hey, what is this? You reading over my shoulder? :laugh:

            L u n a t i c F r i n g e

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            :-O

            1 Reply Last reply
            0
            • L Lost User

              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

              M Offline
              M Offline
              mostafa_pasha
              wrote on last edited by
              #6

              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

              L 1 Reply Last reply
              0
              • M mostafa_pasha

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M mostafa_pasha

                  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

                  K Offline
                  K Offline
                  KingsGambit
                  wrote on last edited by
                  #8

                  I think you can debug into Bitmap::FromHBITMAP() function and see what is going wrong.

                  M 1 Reply Last reply
                  0
                  • K KingsGambit

                    I think you can debug into Bitmap::FromHBITMAP() function and see what is going wrong.

                    M Offline
                    M Offline
                    mostafa_pasha
                    wrote on last edited by
                    #9

                    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); }

                    L K 2 Replies Last reply
                    0
                    • M mostafa_pasha

                      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); }

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      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

                      M 1 Reply Last reply
                      0
                      • M mostafa_pasha

                        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); }

                        K Offline
                        K Offline
                        KingsGambit
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • L Lost User

                          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

                          M Offline
                          M Offline
                          mostafa_pasha
                          wrote on last edited by
                          #12

                          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

                          L 1 Reply Last reply
                          0
                          • M mostafa_pasha

                            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

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            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 use GetLastError() as I suggested previously to check why the call failed.

                            txtspeak is the realm of 9 year old children, not developers. Christian Graus

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups