STA hidden windows under Windows XP
Hi,
From my knowledge about STA, there is one hidden window associated
with each STA based thread. But it seems that knowledge is not correct
under the windwox XP platform.
Under the below sample, the main thread enter the STA apartment by
calling
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
From the main thread, it creates a new thread which also call
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) and enter the STA
apartment.
So now it supposed there are two hidden windows whose class is
OleMainThreadWndClass for each thread's STA apartment. However, it
seems there is only one hidden window there from the main thread. You
can identify it by calling FindWindowEx like below at each thread:
const char szClass[] = "OleMainThreadWndClass";
HWND hWnd = NULL;
DWORD tid4hwnd;
DWORD dwIdsub = ::GetCurrentThreadId();
do {
hWnd = ::FindWindowEx(NULL,hWnd,szClass,NULL);
tid4hwnd = GetWindowThreadProcessId(hWnd,NULL);
} while ( NULL!=hWnd &&
tid4hwnd!=dwIdsub);
At the main thread, it returns a hidden OleMainThreadWndClass window
that belongs to the main thread; at the second thread, it also only
finds the main thread's OleMainThreadWndClass hidden window.
Does that mean the hidden window is sharing by both STA based threads?
If so, is there any document like http://msdn2.microsoft.com/en-us/library/ms809311.aspx#dcomarch_concur
to state the change?
Thanks,
Steve
date: Thu, 13 Dec 2007 17:17:34 -0800 (PST)
author: Steve Zhang