According to the documentation of the GetModuleHandle function, it is unsafe to assume that the handle returned remains valid between the time the handle is returned and the time it is used (most relevant in multithreaded applications). Unfortunately, MFC uses GetModuleHandle unsafely behind the scenes in the class CDllIsolationWrapperBase (afxcomctl32.h).The CDllIsolationWrapperBase class first attempts to query and store for an extended period the handle to the module in question using GetModuleHandle, and if that fails it falls back to LoadLibrary. LoadLibrary increases the reference count, GetModuleHandle does not. If something temporarily loads the module before the first use of this class and unloads it later, the class assumes it's still valid and a crash is likely.
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Operating System Language