Determine the current HINSTANCE?

前端 未结 4 1504
自闭症患者
自闭症患者 2021-01-31 14:07

The HINSTANCE of a win32 application is passed to WinMain, but is there any other way of determining the current HINSTANCE (in case you couldn\'t tell, I\'m very new to win32 pr

4条回答
  •  庸人自扰
    2021-01-31 14:17

    The function AfxGetStaticModuleState() does the trick. If you call it within a dll, the functions returns the handle to the dll, if the call within a exe it returns the handle to the executable.

    DWORD size;
    TCHAR fileName [MAX_PATH];
    HMODULE hModule = AfxGetStaticModuleState()->m_hCurrentInstanceHandle;
    ::GetModuleFileName (hModule, fileName, size);
    

提交回复
热议问题