Click to See Complete Forum and Search --> : Calling a COM Object from another thread


Londo Molari
September 23rd, 1999, 08:21 AM
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.

Londo Molari
September 23rd, 1999, 09:12 AM
Call me stupid. I've just found out that I was using COInitalize(NULL); ranther than CoInitalizeEx(NULL, COINIT_MULTITHREADED);

Sorry!

Chris Mc C
September 23rd, 1999, 09:21 AM
Stupid!!!

Couldn't resist that.

Chris Mc Clements
*****************