Since the MFC TestRunner runs each test on a separate
thread, the COM components that I was trying to test
were failing because CoInitialize was not called for
the thread that separate thread.
My fix was simple. Just call CoInitialize and
CoUninitialize in ActiveTest::threadFunction:
// Simple execution thread. Assuming that an
// only creates one of these at a time.
UINT ActiveTest::threadFunction (LPVOID thisInstance)
ActiveTest *test = (ActiveTest *)thisInstance;
bool comInit = SUCCEEDED( CoInitialize( NULL ) );
if ( comInit )
This works for me because my components are STA but a
more general solution is needed to handle testing in
other threading models. Perhaps by passing in some
parameters to the TestRunner constructor.
Log in to post a comment.