I want to have a static global std::unordered_map in the cpp of my entry point for my COM server.
relevant header code:
typedef unordered_map<HWND,IMyInterface*> MyMapType;
relevant body:
static MyMapType MyMap;
void MyFunction(HWND hWnd, IMyInterface* pObj){
MyMap[hWnd] = pObj;
}
HINSTANCE g_hInstModule = NULL;
BOOL WINAPI DllMain ( __in HINSTANCE hInstDLL, __in DWORD fdwReason, __in LPVOID lpvReserved )
{
if( fdwReason == DLL_PROCESS_ATTACH )
{
g_hInstModule = hInstDLL;
return true;
}
else if( fdwReason == DLL_PROCESS_DETACH )
{
return true;
}
return false;
}
MyCoClass::MyCoClass()
{
DRM_Refcount = 1;
}
HRESULT STDMETHODCALLTYPE MyCoClass::InitMyCoClass()
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
//replace with make window code
MyFunction(hWnd,ISomeInterface);
return S_OK;
}
The only way I can get this to work is be making a map_type pointer and creating an instance of map_type on the heap and pointing at it with the global pointer. :/
WHY?