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. LoadBitmap returns NULL

LoadBitmap returns NULL

Scheduled Pinned Locked Moved C / C++ / MFC
performance
10 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.
  • E Offline
    E Offline
    ElizabethC
    wrote on last edited by
    #1

    I want to display a JPEG file at the picture control. I created a memory variable m_hBitmap at the CDialog class and have the interface to process the following code when the Open button is clicked. But line #2 always returns NULL. CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; //line #1 m_hBitmap = (HBITMAP)::LoadBitmap(NULL, file_name); //line #2 m_thumbnail.SetBitmap(m_hBitmap); //line #3 Elizabeth

    M D 2 Replies Last reply
    0
    • E ElizabethC

      I want to display a JPEG file at the picture control. I created a memory variable m_hBitmap at the CDialog class and have the interface to process the following code when the Open button is clicked. But line #2 always returns NULL. CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; //line #1 m_hBitmap = (HBITMAP)::LoadBitmap(NULL, file_name); //line #2 m_thumbnail.SetBitmap(m_hBitmap); //line #3 Elizabeth

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      are you sure LoadBitmap can load jpg files ?


      Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )

      1 Reply Last reply
      0
      • E ElizabethC

        I want to display a JPEG file at the picture control. I created a memory variable m_hBitmap at the CDialog class and have the interface to process the following code when the Open button is clicked. But line #2 always returns NULL. CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; //line #1 m_hBitmap = (HBITMAP)::LoadBitmap(NULL, file_name); //line #2 m_thumbnail.SetBitmap(m_hBitmap); //line #3 Elizabeth

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Are you sure that the first parameter to LoadBitmap() can be NULL? The docs do not indicate such. Have you checked the return value of GetLastError()? That might tell you exactly what is happening! I suspect Max's comment is more in line with what is happening.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        E 1 Reply Last reply
        0
        • D David Crow

          Are you sure that the first parameter to LoadBitmap() can be NULL? The docs do not indicate such. Have you checked the return value of GetLastError()? That might tell you exactly what is happening! I suspect Max's comment is more in line with what is happening.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          E Offline
          E Offline
          ElizabethC
          wrote on last edited by
          #4

          I tried openning a bitmap file, but still getting a NULl return. Here is the updated code: CString file_name = "c:\\gis\\aspjpeg\\new_file.bmp"; //line #1 m_hBitmap = (HBITMAP)::LoadBitmap(NULL, file_name); //line #2 DWORD error = GetLastError(); The error code is 1814 which is resource file not found. Elizabeth

          D 1 Reply Last reply
          0
          • E ElizabethC

            I tried openning a bitmap file, but still getting a NULl return. Here is the updated code: CString file_name = "c:\\gis\\aspjpeg\\new_file.bmp"; //line #1 m_hBitmap = (HBITMAP)::LoadBitmap(NULL, file_name); //line #2 DWORD error = GetLastError(); The error code is 1814 which is resource file not found. Elizabeth

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            ElizabethC wrote: The error code is 1814 which is resource file not found. Of course, because a resource named "c:\\gis\\aspjpeg\\new_file.bmp" does not exist in a module having an instance handle of 0. You need to use a non-NULL instance handle, and the specified bitmap should not contain any path information. I think you need to use LoadImage() instead.


            Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

            E 1 Reply Last reply
            0
            • D David Crow

              ElizabethC wrote: The error code is 1814 which is resource file not found. Of course, because a resource named "c:\\gis\\aspjpeg\\new_file.bmp" does not exist in a module having an instance handle of 0. You need to use a non-NULL instance handle, and the specified bitmap should not contain any path information. I think you need to use LoadImage() instead.


              Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

              E Offline
              E Offline
              ElizabethC
              wrote on last edited by
              #6

              I have just looked up LoadImage(). It also requires a instance handle. Can you suggest what HINSTANCE should I use in a CDialog class? The picture will be displayed at the picture control which is a CStatic control. Elizabeth

              D 1 Reply Last reply
              0
              • E ElizabethC

                I have just looked up LoadImage(). It also requires a instance handle. Can you suggest what HINSTANCE should I use in a CDialog class? The picture will be displayed at the picture control which is a CStatic control. Elizabeth

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                ElizabethC wrote: It also requires a instance handle. Which can be 0.


                Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                E 1 Reply Last reply
                0
                • D David Crow

                  ElizabethC wrote: It also requires a instance handle. Which can be 0.


                  Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                  E Offline
                  E Offline
                  ElizabethC
                  wrote on last edited by
                  #8

                  I got it working with the bitmap file with the return handle: CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); However, it the handle is NULL when loading a JPEG file: CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; // CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; //line #1 m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); Do you know how to load a JPEG file into the picture control? Elizabeth

                  P D 2 Replies Last reply
                  0
                  • E ElizabethC

                    I got it working with the bitmap file with the return handle: CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); However, it the handle is NULL when loading a JPEG file: CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; // CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; //line #1 m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); Do you know how to load a JPEG file into the picture control? Elizabeth

                    P Offline
                    P Offline
                    PJ Arends
                    wrote on last edited by
                    #9

                    ElizabethC wrote: Do you know how to load a JPEG file into the picture control? Use GDIPlus::Bitmap class Use IPicture and ::OleLoadPicture() or OleLoadPicturePath() functions.


                    [

                    ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

                    1 Reply Last reply
                    0
                    • E ElizabethC

                      I got it working with the bitmap file with the return handle: CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); However, it the handle is NULL when loading a JPEG file: CString file_name = "c:\\gis\\aspjpeg\\root.jpeg"; // CString file_name = "c:\\gis\\aspjpeg\\file_new.bmp"; //line #1 m_hBitmap = (HBITMAP)LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DWORD error = GetLastError(); Do you know how to load a JPEG file into the picture control? Elizabeth

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      ElizabethC wrote: However, it the handle is NULL when loading a JPEG file: Maybe it's not designed to work with non-BMP images.


                      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                      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