Thread: Bitmap::LoadImage Returns InvalidParameter only while Debugging

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    4

    Bitmap::LoadImage Returns InvalidParameter only while Debugging

    I am having a very strange issue in regards to loading an image into my program.

    When I'm in debug mode, the image status keeps telling me "Invalid Parameter", however, when I run the same program normally, it loads the image no problem.

    I've ruled out directory names and such, and now I am just confused.

    Here's the code I've been using (It's a bit messy as I've been trying various things to get it to work):

    Code:
    void OnPaint(HDC hdc)
    {
        Bitmap myImage(L"a.png");
        Graphics mygfx(hdc);
    
        Status st = myImage.GetLastStatus();
    
        if(Ok == st)
        {
            mygfx.DrawImage(&myImage,60,10);
        }
        else if(InvalidParameter == st)
        {
            MessageBox(NULL,L"InvalidParameter",L"What",MB_OK);
    
        }
    
    }

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by Hydrogen99 View Post
    I've ruled out directory names and such, and now I am just confused.
    You'll want to double check, InvalidParameter is the error you get when the file isn't found. If you're using Visual Studio the default current directory is the one which contains the vcproj file, not where the exe ends up (which it would be if you just click on the exe).

    Also, creating those two objects should be done in an OnCreate method not OnPaint. You don't want to be loading and freeing them everytime you have to paint.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    Oh I didn't know that it was in the project directory. Thanks. Turns out the method I was using to rule out directories just returned where the EXE name was and not the path. I've now corrected this and have it working. (For anyone having the same issue, I used GetCurrentDirectory).

    I do know I have to put those in onCreate, I was just copying the example from MSDN which had them in onPaint.

    Thanks for the help adeyblue! Much appreciated!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DialogBox returns -1. GetLastError returns error 1813.
    By Benji Wiebe in forum Windows Programming
    Replies: 14
    Last Post: 09-26-2011, 10:21 AM
  2. LoadImage()
    By Gordon in forum Windows Programming
    Replies: 15
    Last Post: 12-22-2007, 06:16 PM
  3. LoadImage()
    By SniperSAS in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2006, 06:39 PM
  4. main returns int -- compiler returns nonsense
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-15-2005, 09:53 AM
  5. I'm having so much trouble with LoadImage()!!!
    By minesweeper in forum Windows Programming
    Replies: 2
    Last Post: 05-03-2002, 04:28 PM