global std::unordered_map com server init problems

Posted by PrettyFlower on Stack Overflow See other posts from Stack Overflow or by PrettyFlower
Published on 2010-06-05T22:37:22Z Indexed on 2010/06/05 22:42 UTC
Read the original article Hit count: 261

Filed under:

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?

© Stack Overflow or respective owner

Related posts about com