OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Rajesh G (G.RajeshBLR.SPCNL.CO.IN)
Date: Mon Jul 30 2001 - 08:43:01 CDT

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Hi,

    I have an COM Server which is an EXE. I have a client which launches
    multiple threads. From each thread, I want to call CoCreateInstance of the
    Component. In one of the functions of the Interface, I have a function which
    takes some time to execute. I don't want the other threads to be blocked
    because of the one of thread. How to come over this problem. Any Suggestions
    Please...

    Thanks in Advance,

    Rajesh G.

    The Sample Code. This is similar to what I require.

    //Component
    STDMETHODIMP CApartComp::GetData(int nIndex)
    {
            if(nIndex < 4)
            {
                    for(int i(0); i < 10000000000; i++);
            }
            ::MessageBox(NULL,"Both Component","Component",MB_OK);
            return S_OK;
    }

    //Client Code

    UINT ThreadProc(LPVOID pVoid)
    {
            int* pIndex = (int*) pVoid;
            TRACE("Index Number in Thread is %d\n", *pIndex);
            CoInitialize(NULL);
            IApartInterface* pIntr;
            HRESULT hRes = CoCreateInstance(CLSID_ApartComp,NULL,

    CLSCTX_ALL,IID_IApartInterface,(void**)&pIntr);
            if(FAILED(hRes))
            {
                    AfxMessageBox("Error Creating Component");
                    return 1;
            }
            pIntr->GetData(*pIndex);
            return 0;
    }

    void CMainFrame::OnGetdata()
    {
            for(int i(0); i < 5; i++)
            {
                    int nIndex = i+1;
                    TRACE("Index from mainframe is %d\n", nIndex);
                    CWinThread* pThread = AfxBeginThread(ThreadProc,(void*)
    &nIndex,THREAD_PRIORITY_NORMAL,CREATE_SUSPENDED);
                    ResumeThread(pThread->m_hThread);
            }

    }

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM