ALT/COM and createthread question
Problem:
Ok, Ive created COM through the Wizard and added one method and one connection point.
When the method gets called im doing createthread to static function and doing a createevent with RegNotifyChangeKeyValue.
Once the event is received im trying to raise an event via a connectionpoint.
This is my static function:
static DWORD WINAPI CThread(CTestMe *pthis)
{ DWORD dwFilter = REG_NOTIFY_CHANGE_NAME |
REG_NOTIFY_CHANGE_ATTRIBUTES |
REG_NOTIFY_CHANGE_LAST_SET |
REG_NOTIFY_CHANGE_SECURITY;
HKEY hMainKey;
lErrorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0, KEY_NOTIFY, &hKey);
if (lErrorCode != ERROR_SUCCESS)
{
return -1;
}
// Create an event.
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hEvent == NULL)
{
return -1;
}
// Watch the registry key for a change of value.
lErrorCode = RegNotifyChangeKeyValue(hKey,
TRUE,
dwFilter,
hEvent,
TRUE);
if (lErrorCode != ERROR_SUCCESS)
{
return -1;
}
if (WaitForSingleObject(hEvent, INFINITE) == WAIT_FAILED)
{
return -1;
}
lErrorCode = RegCloseKey(hKey);
if (lErrorCode != ERROR_SUCCESS)
{
return -1;
}
if (!pthis)
{
MessageBox( NULL, "null ptr", "main", MB_OK );
}
pthis->Fire_Done(0); //this causes app to crash.
return 0;
}
here is my method:
STDMETHODIMP CTestMe::AddNums(int x, int y)
{
HANDLE hThread;
char szMsg[80];
hThread=CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)CThread,this,0,(LPDWORD)&d_threadID );
if (hThread==NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
return S_FALSE;
}
return S_OK;
}
Im passing the this pointer to my createthread function. If I add another method, I can call it via my passed ptr. But it fails when I try calling the event.
Any clues on what im doing wrong??
Thanks
PacketVB