Hello guys
I have a problem with an out of process COM-server. I inject a DLL into a foreign process and this DLL registers some Classes as local servers. This is done in the following way:
1. For each object the following registry entries are created:
HKLM\SOFTWARE\Classes\CLSID\{GUID OF CLASS}\LocalServer32
and its default value is set to the path of the executable of the foreign process.
2. For each object CoRegisterClassObject is called like that:
CoRegisterClassObject(riid, static_cast<IUnknown*>(factory), CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &token);
So far this call always returned S_OK.
3. After all objects are registered
CoResumeClassObjects
is called and the message loop is entered.
Now the consuming application wants to create such an object and calls CoCreateInstance with CLSCTX_LOCAL_SERVER. Even tough the foreign process is running and has registered its objects the process is started again (at least it means that the object was correctly put in the registry) and the request is not sent to the already running one. But whats the reason for that beahaviour? Did i forget something about telling the OS that my objects are available?
On a sidenote there is another weird thing. If i remove the message loop and replace it with a WaitForSingleObject in the following way:
HANDLE hEvent = NULL;
unsigned long __stdcall ServerThread(LPVOID)
{
CoInitialize(NULL);
REG_CLASS(TestClass);
CoResumeClassObjects();
MSG msg;
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
std::cout << "Waiting for event" << std::endl;
WaitForSingleObject(hEvent, INFINITE);
std::cout << "Event set!" << std::endl;
UNREG_CLASS(TestClass);
ExitThread(0);
}
And try to set it in DllMain like that:
BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID)
{
if(reason == DLL_PROCESS_DETACH)
{
if(hEvent != NULL)
{
SetEvent(hEvent);
std::cin.get();
}
}
return TRUE;
}
I get the output that its waiting for the event and with other outputs i also see that SetEvent returns TRUE but "Event set" is never printed to the console. Why is the event not working? I also checked that the events are the same and they are.
Thanks for any help
Regner