c++win32-processhinstance

Are win32 hInstances unique?


I’m writing a cache handler that needs a unique ID number for every instance of the application, so that when someone has two projects open in two instances, the caches don’t get confused. According to this thread, it appears the HINSTANCE passed to WinMain is a handle to the module, which could simply be the exe, not necessarily a unique process ID.

The thread seems to say that information about the module/process to be run is brought into memory only once, and the HINSTANCE is a handle to that. Does that mean the HINSTANCE can’t be used as a unique identifier for the process because they all point to the same module? Or am I mistaken?


Solution

  • HINSTANCE is mostly obsolete, a holdover from 16-bit days. It'll have the same value for all instances of your application.

    For a unique process ID, use GetCurrentProcessId