P. Avery
P. Avery

Reputation: 809

Win32 LoadImage() from File Error

Sorry if this is duplicate but I can't find answer elsewhere. I am simply trying to load an image during runtime using the LoadImage() function of WINAPI. I receive the error code(8) which indicates that there is not enough storage space(error codes found here).

the file is relatively small(2.5kb) so I wonder if there is problem with my code:

void OnCreate()
{
...
HBITMAP hbmDeck = (HBITMAP)LoadImage(hInstance, L"standard.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

    DWORD err = GetLastError();
    HBITMAP hbmT = SelectBitmap(hdc, hbmDeck);
    if(!hbmT)
    {
        MessageBox(NULL, L"Failed to LoadImage - 'hbmDeck'", L"OnCreate()", MB_OK);
        PostMessage(hwnd, WM_DESTROY, NULL, NULL);
    }
...
}

Upvotes: 1

Views: 3847

Answers (1)

Gunner
Gunner

Reputation: 5884

Yeah, some of the API return error codes are a bit cryptic and don't fit the error.

The file you are trying to load "standard.bmp" is a file on the disk NOT in the resource section right? Well to load a file from the disk, the fist parameter of LoadImage (hInst) has to be NULL and the fuLoad flag needs to include LR_LOADFROMFILE which you correctly have.

Upvotes: 2

Related Questions