Get HModule from inside a DLL

前端 未结 3 900
挽巷
挽巷 2021-01-19 05:43

I need to load some resource from my DLL (i need to load them from the DLL code), for doing that I\'m using FindResource.

To do that i need the HModule of the DLL.

3条回答
  •  情歌与酒
    2021-01-19 05:50

    Depending upon how your software is architected, you may not have access to DllMain or the code that wants the resource may not even know it's inside a DLL or exe!

    The DLLMain function is given the DLL's module handle. Store it in a globally accessible variable.

    Or, lookup the module based upon a function known to the local code:

    // Determine the module handle by locating a function
    // you know resides in that DLL or exe
    HMODULE hModule;
    GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
                       GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
                       (LPCSTR)&myDLLfuncName, &hModule);
    
    HRSRC hRscr = FindResource(hModule, ............);
    

提交回复
热议问题