LoadImage()

This is a discussion on LoadImage() within the Windows Programming forums, part of the Platform Specific Boards category; I have tried and tried, but I'll be damned if I can get this function to work properly. Everything I ...

  1. #1
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175

    LoadImage()

    I have tried and tried, but I'll be damned if I can get this function to work properly. Everything I have read online acts as if this is such a simple thing, but everything I try fails. I have even copied and pasted lines from programs off the internet, and this thing still refuses to work for me.

    The way I call it looks like this:

    Code:
    TImage = (HBITMAP)LoadImage(NULL, Tmem.DisplayImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
    Assuming TImage is an HBITMAP and Tmem.DisplayImage is a string with the filename in it, what am I doing wrong? I have checked to see what Tmem.DisplayImage contains when I call this, and it correctly contains the path.

    Thanks in advance to anyone who helps.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The LR_DEFAULTSIZE flag is not used for bitmaps. Also, is the file a valid .bmp file? What error value are you getting from GetLastError after the failed call?

  3. #3
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    don't use NULL for first parameter, use your programs HINSTANCE, if you don't have it stored use GetModuleHandle(NULL)

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    Quote Originally Posted by Darryl
    don't use NULL for first parameter, use your programs HINSTANCE, if you don't have it stored use GetModuleHandle(NULL)
    Soz Dazza, but that's only if you're looking to load a resource from that module as an image. If you're loading an external file, this should be NULL and LR_LOADFROMFILE defined in the flags.
    Last edited by SMurf; 04-19-2006 at 10:32 AM.

  5. #5
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Quote Originally Posted by anonytmouse
    The LR_DEFAULTSIZE flag is not used for bitmaps. Also, is the file a valid .bmp file? What error value are you getting from GetLastError after the failed call?
    My call now looks like this:

    Code:
    TImage = (HBITMAP)LoadImage(NULL, Tmem.DisplayImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    And the call to get last error looks like this:

    Code:
    error = GetLastError();
    cout<< error;
    Which prints '2'

    I have never used GetLastError() before so I don't know what this means, error is of type DWORD

    Edit: After surfing MSDN I found that 2 means "File not found" but when I print Tmem.DisplayImage it successfully reads "F:\drive\projects\function tests\poop.bmp"
    Last edited by SniperSAS; 04-19-2006 at 11:56 AM.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You need to use escape characters in the path ie.
    Code:
    "F:\\drive\\projects\\function tests\\poop.bmp"
    or, alternatively, use '/' syntax which LoadImage should be able to understand:
    Code:
    "F:/drive/projects/function tests/poop.bmp"
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Quote Originally Posted by Ken Fitlike
    You need to use escape characters in the path ie.
    Code:
    "F:\\drive\\projects\\function tests\\poop.bmp"
    or, alternatively, use '/' syntax which LoadImage should be able to understand:
    Code:
    "F:/drive/projects/function tests/poop.bmp"
    Thanks man, that works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadImage()
    By Gordon in forum Windows Programming
    Replies: 15
    Last Post: 12-22-2007, 05:16 PM
  2. LoadImage() fooled me!
    By Sebastiani in forum Windows Programming
    Replies: 1
    Last Post: 05-07-2002, 10:20 PM
  3. I'm having so much trouble with LoadImage()!!!
    By minesweeper in forum Windows Programming
    Replies: 2
    Last Post: 05-03-2002, 04:28 PM
  4. LoadImage doesn't work when my program is accesing the hardrive
    By pinkcheese in forum Windows Programming
    Replies: 2
    Last Post: 04-20-2002, 12:39 AM
  5. 'The parameter is incorrect' - LoadImage
    By DarkAvenger in forum Windows Programming
    Replies: 1
    Last Post: 04-12-2002, 02:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21