• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Visual C++ Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Visual C++ Developer Center > Visual C++ Forums > Visual C++ Language > IRunningObjectTable::GetObject return a error
Ask a questionAsk a question
Search Forums:
  • Search Visual C++ Language Forum Search Visual C++ Language Forum
  • Search All Visual C++ Forums Search All Visual C++ Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerIRunningObjectTable::GetObject return a error

  • Monday, July 07, 2008 4:09 AMliixixi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Hi, 
        When I use RunningObjectTable, there is a puzzling error. Why I can't get a right pointer by IRunningObjectTable::GetObject.

        Here is the test code:

    int main(int argc, char* argv[])
    {
        CoInitialize(NULL);

        {
            CComPtr<IHello> ptr;
            ptr.CoCreateInstance(CLSID_Hello);

            ptr->Hello();    // I can InternalAddRef() in this function.
        }                         // So, when ptr is auto released, the object in COM server end will not be desstructed.

        {
            HRESULT hr = S_OK;
            IRunningObjectTable* pROT = NULL;
           
            const WCHAR szDelim[2] = L"!";
            IMoniker*   pmkService = NULL;
           
            CComBSTR    bstrMkItemName("12345678");
           
            hr = CreateItemMoniker( szDelim, bstrMkItemName, &pmkService );
            if( FAILED( hr ) )
            {
                return hr;
            }
           
           
            hr = GetRunningObjectTable( 0, &pROT );
            if( FAILED( hr ) )
            {
                return hr;
            }
           
           
            IUnknown* pUnk;
            pROT->GetObject(pmkService, &pUnk);          // after this line, why pUnk = NULL?

            IHello* iptr;
            pUnk->QueryInterface(&iptr);

            iptr->Hello();
        }

     return 0;
    }    

    The code in COM server end:

    STDMETHODIMP CHello::Hello()
    {
        MessageBox(NULL, "Hello", "", MB_OK);

        HRESULT hr = S_OK;
        IRunningObjectTable* pROT = NULL;

        const WCHAR szDelim[2] = L"!";
     IMoniker*   pmkService = NULL;

        CComBSTR    bstrMkItemName("12345678");

     hr = CreateItemMoniker( szDelim, bstrMkItemName, &pmkService );
        if( FAILED( hr ) )
     {
            return hr;
     }


     hr = GetRunningObjectTable( 0, &pROT );
     if( FAILED( hr ) )
     {
            return hr;
     }

     hr = pROT->Register(0, this, pmkService, &m_dwRegister);

        this->InternalAddRef();
     return S_OK;
    }



     

    thanks.
    liixixi
    • ReplyReply
    • QuoteQuote
     

Answers

  • Tuesday, July 08, 2008 3:15 AMliixixi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    The problem has reseloved, it should use ROTFLAGS_REGISTRATIONKEEPSALIVE to register the object to ROT.
    • Marked As Answer byYan-Fei WeiMSFT, ModeratorFriday, July 11, 2008 2:45 AM
    •  
    • ReplyReply
    • QuoteQuote
     

All Replies

  • Monday, July 07, 2008 6:13 PMBrian MuthMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    What is the value of HRESULT returned by GetObject()?

    Is the COM Server a DLL, a DCOM executable or a DCOM service?
    • ReplyReply
    • QuoteQuote
     
  • Tuesday, July 08, 2008 5:06 AMBrian MuthMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Out of curiosity, did the HRESULT value returned by GetObject() help you deduce the problem?
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement