IRunningObjectTable::GetObject return a error
- 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
Antworten
- The problem has reseloved, it should use ROTFLAGS_REGISTRATIONKEEPSALIVE to register the object to ROT.
- Als Antwort markiertYan-Fei Wei Freitag, 11. Juli 2008 02:45
Alle Antworten
- What is the value of HRESULT returned by GetObject()?
Is the COM Server a DLL, a DCOM executable or a DCOM service? - The problem has reseloved, it should use ROTFLAGS_REGISTRATIONKEEPSALIVE to register the object to ROT.
- Als Antwort markiertYan-Fei Wei Freitag, 11. Juli 2008 02:45
- Out of curiosity, did the HRESULT value returned by GetObject() help you deduce the problem?

