In one .exe application WinMain, the entry point has a parameter HINSTANCEthat must be a pseudo-descriptor (since it is equivalent GetModuleHandle(NULL)that returns a pseudo-descriptor, according to MSDN). I assume this is pseudo, because there are both special values (for example, NULLto denote an entry point module) and constants used to return an error (something less than 32).
MSDN explicitly describes it as a pointer (currently equivalent HMODULE) to the base address of the module; we know that this may have a completely different meaning for 16-bit applications, but in a 32/64 bit world, each process has its own address space, then its exact value is useless, probably always the same for each instance and absolutely pointless outside its process .
All of this, this is my first question : can we (formally, despite the fact that MSDN seems contradictory), assume that it HINSTANCEis a pointer (even to be honest, I do not see any use for this), or is it better to assume that this ( pseudo) handle (where its value is opaque)?
Suppose a value is opaque, my second question is : is its value valid for each process or for a thread?
We may think that the process descriptor is valid for each process, but several (angular) cases make me think that we should consider it valid for each thread. If these corner cases exist then (even if they usually work as expected for each process), we rely on implementation details, undefined behavior can be changed for different architectures, versions, environments.
, ( , ): DLL , ( ) (, ). , ( , , V++, #pragma data_seg comment(linker)). ( DLL), HINSTANCE ( ), IMO HINSTANCE, A ( DLL) HINSTANCE, B. : , HINSTANCE, GetModuleHandle(NULL), .
, , HINSTANCE, , WinMain. , , , CreateWindow() ( scope - , , , )?
void createToolbox(const char* windowName, HINSTANCE hInstance) {
CreateWindow(windowClass, windowName,
WS_OVERLAPPEDWINDOW,
0, 0, 640, 480,
0, 0, hInstance, NULL);
}
, , HMODULE, Windows Mobile...
NULL, GetModuleHandle - . [...] - - , . , .
, ( ).