CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    Somerset, England
    Posts
    20

    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.


  2. #2
    Join Date
    Aug 1999
    Location
    Somerset, England
    Posts
    20

    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!


  3. #3
    Join Date
    Sep 1999
    Location
    Dundee, Scotland, UK
    Posts
    17

    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
  •  





Click Here to Expand Forum to Full Width

Featured