Mixed COM Apartment models
COM
1
Posts
1
Posters
2
Views
1
Watching
-
Hi, I have the following problem. From within the same thread I wish to call two components with different threading models. Number one component will instantiate another component and receive events through connection points. This component will have to be Free-threaded or the call to ICOnnectionPoint::Advise() will fail. The other component should instantiate the IShellLink interface to create a shortcut. Take a look at this sample:
// COINIT\_MULTITHREADED is neccesary because one component is free-threaded ::CoInitializeEx(NULL, COINIT\_MULTITHREADED); HRESULT hr = S\_OK; IMulti\* p1 = NULL; IShellLink \*psl=NULL; hr = ::CoCreateInstance(CLSID\_ShellLink, NULL, CLSCTX\_INPROC\_SERVER, IID\_IShellLink, (LPVOID\*) &psl); ASSERT(SUCCEEDED(hr)); hr = CoCreateInstance(CLSID\_Multi, NULL, CLSCTX\_INPROC\_SERVER, \_\_uuidof(IMulti), (void\*\*)&p1); ASSERT(SUCCEEDED(hr)); p1->Release(); psl->Release(); ::CoUninitialize();
The problem is that the call to
hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl)
fails when CoInitializeEx has been called with the COINIT_MULTITHREADED parameter Any help will be greatly appreciated Christian Skovdal Andersen