Home > Mobile >  Win api - error 1813 after calling LoadImage
Win api - error 1813 after calling LoadImage

Time:01-31

I have a dynamic library which uses LoadImage function:

HINSTANCE hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(wnd, GWLP_HINSTANCE);
HBITMAP hBitMap = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(resId), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

That library is linked to the main application (exe). When the application calls a library function which calls LoadImage I get Win api error 1813. hInstance refers to the exe file. How to fix that ?

CodePudding user response:

Think that problem lies you want load image from dll but instead your code trying to load resource from exe.

CodePudding user response:

LoadImage works when I get HINSTANCE this way:

HMODULE GetModule()
{ 
    HMODULE hMod = NULL;
    GetModuleHandleEx(
        GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
        (LPCTSTR)GetModule,
        &hMod);

    return hMod;
}

HINSTANCE hInstance = (HINSTANCE)GetModule();

Please review my answer.

  • Related