Article ID: 189427
Article Last Modified on 10/19/2005
Date Time Version Size File name ------------------------------------------------------- 05/29/2001 06:23p 2.40.4518.0 143,632 Asycfilt.dll 05/29/2001 06:23p 2.40.4518.0 626,960 Oleaut32.dll 05/29/2001 06:23p 5.0.4518.0 164,112 Olepro32.dll
#define _WIN32_DCOM
#include <windows.h>
void main()
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
VARIANT var,var1;
VariantInit(&var);
VariantInit(&var1);
BSTR str = SysAllocString(L"Test");
var.vt = VT_BSTR;
var.bstrVal = str;
VariantChangeType(&var, &var, 0, VT_I2);
VariantClear(&var);
VariantClear(&var1);
while (1)
{
;
}
CoUninitialize();
}
Run this application. Run another application that broadcasts a message
(for example, double click a .doc icon on the desktop). A message is
broadcast to all the top-level windows that are using either SendMessage or
a non-blocking variation of the SendMessage API (such as
SendMessageTimeout). The broadcasting application is either blocked (hung)
indefinitely or hung for the period of time it takes the call to timeout.
#define _WIN32_DCOM
#include <windows.h>
HANDLE g_EventHandle;
DWORD WINAPI SecondaryThread(LPVOID pInputParam)
{
HRESULT hr = S_OK;
// Initialize COM with Mutithreaded.
hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
VARIANT var, var1;
VariantInit(&var);
VariantInit(&;var1);
BSTR str = SysAllocString(L"Test");
var.vt = VT_BSTR;
var.bstrVal = str;
// This will create a hidden window in this thread.
hr = VariantChangeType(&var, &var, 0, VT_I2);
// Set the global event.
SetEvent(g_EventHandle);
VariantClear(&var);
VariantClear(&var1);
MSG msg;
// msg-pump.
while (GetMessage(&msg, NULL, 0, 0))
{
// This was the message -- time to work.
if ( msg.message == WM_USER+1)
{
// When done:
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
CoUninitialize();
return 0;
}
void main()
{
DWORD dwThreadID;
HANDLE hThread;
// Create a global Event.
g_EventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
// Spin the secondary thread.
hThread = CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)
SecondaryThread,0,0,&dwThreadID);
DWORD ret;
// Wait until the event is set in the secondary thread.
ret = WaitForSingleObject(g_EventHandle, INFINITE);
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Any other code.
while (1)
{
;
}
CoUninitialize();
// Clean up the secondary thread.
PostThreadMessage(dwThreadID,WM_USER+1,0,0);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
Additional query words: OLE COM
Keywords: kboleapp kbqfe kbolearc kbprb kbhotfixserver KB189427