c++ unhandled exception LoadImage() with MAKEINTRESOURCE

0

I'm having a problem to add a bitmap image to a static control box, i got an unhandled exception when i run my program. Here's my code.

FROM RC FILE :

ID_ICON1    BITMAP  "icon1.bmp"

CPP FILE :

HANDLE bIcon1;
HWND hIcon;             
hIcon = CreateWindowEx(0, "Static", NULL, WS_CHILD | WS_VISIBLE|SS_BITMAP, 250, 100, 100, 100, hwnd, NULL, GetModuleHandle(NULL), NULL);
bIcon1 = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON1), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE| LR_DEFAULTSIZE);

If i use full path i get no error and the bmp shows correctly :

bIcon1 = LoadImage(GetModuleHandle(NULL), "c:\\icon1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE| LR_DEFAULTSIZE);

Thanks for helping :)

edit: the line of the exception is this one:

bIcon1 = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON1), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE| LR_DEFAULTSIZE);

the message exception is : Unhandled exception at 0x7768e41b in windows2.exe: 0xC0000005: Access violation reading location 0x000001f4.

windows2.exe!WndProc(HWND__ * hwnd, unsigned int msg, unsigned int wParam, long lParam) Line 153 + 0x27 bytes C++

c++
resources
loadimage
asked on Stack Overflow Aug 8, 2012 by yves • edited Aug 8, 2012 by yves

1 Answer

2

You are passing LR_LOADFROMFILE but the second parameter is not a file name. Delete that flag.

answered on Stack Overflow Aug 8, 2012 by Raymond Chen

User contributions licensed under CC BY-SA 3.0