Date: 2008mar7
Date: 2025jul20
Language: C/C++
OS: Windows
Keywords: instance, handle, self
Q. Win32: get the instance of the current program when I don't have access to the WinMain() parameters
A. In regular Win32 do this:
HINSTANCE hMyInstance = GetModuleHandle(NULL);
As you mentioned, its the first parameter to your WinMain() function:
int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hInstP, LPSTR lpCmdLine, int nCmdShow) {
HINSTANCE hMyInstance = hInst;
// ...
}
In MFC:
HINSTANCE hMyInstance = AfxGetInstanceHandle();