|
-
September 23rd, 1999, 08:21 AM
#1
Calling a COM Object from another thread
I have a dialog which creates an instance of a COM service. It then creates a thread which creates an instance of another COM Service. I pass a pointer to the class to the thread and it uses this pointer to call functions from the class.
The problem I have is when I try and call a function from the thread and that function then calls a function from the COM Serivce the marshaling DLL fails on NdrProxySendReceive().
What am I doing wrong.
I've cut out alot of the code for space reasons.
// Main UI Thread
MyDlg::RunCode()
{
CoInitalize();
hr = CoCreateInstance(CLSID_DMIetmUnload, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (LPVOID*&m_pIUnknown);
CWinThread* pThread = NULL;
pThread = AfxBeginThread(UnloadModuleThreadProc, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED)
CoFreeUnusedLibraries();
CoUninitialize();
}
// Called from thread
bool CGenerationDlg::GetModule(ModuleInfo& miData)
{
// This is the call that fails. WHY?
m_pIDMIetmUnload->GetDataModuleInformation(Publication);
}
// Thread Function
UINT UnloadModuleThreadProc(LPVOID pParam)
{
CGenerationDlg* pDlg = (CGenerationDlg*)pParam;
CoInitialize(NULL);
// Calls Function in class
pDlg->GetModule(moduleInfo);
pIDMUnload->Release();
CoFreeUnusedLibraries();
CoUninitialize();
}
Regards,
James.
-
September 23rd, 1999, 09:12 AM
#2
Re: Calling a COM Object from another thread
Call me stupid. I've just found out that I was using COInitalize(NULL); ranther than CoInitalizeEx(NULL, COINIT_MULTITHREADED);
Sorry!
-
September 23rd, 1999, 09:21 AM
#3
Re: Calling a COM Object from another thread
Stupid!!!
Couldn't resist that.
Chris Mc Clements
*****************
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|