none
COM interop with C#: Using the Running Object Table RRS feed

  • Question

  • Hi all,

    My problem is really a lack of useful documentation - thanks for any ideas on this:

    I've successfully created a C# class for my COM object and registered it in the ROT, by calling Register on the following interface:

    System.Runtime.InteropServices.ComTypes.IRunningObjectTable

    (http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comtypes.irunningobjecttable.register.aspx)

    Here's its signature:

    int Register( int grfFlags, Object punkObject, IMoniker pmkObjectName )
    This seems to work perfectly, and I can use the registered object. However I now want to be able to revoke the object from the ROT, which I can presumably do using the Revoke method on the same interface, which seems to complement the Register method:

    void Revoke( int dwRegister )
    The problem is that, unlike the COM version, the interop version of the Register method's signature does not take a reference to this value and set it, so I don't know how to obtain it. Here's the COM signature of the Register method, showing the extra argument I need:

    HRESULT Register(  DWORD grfFlags, IUnknown * punkObject, IMoniker * pmkObjectName, DWORD * pdwRegister );
    (http://msdn.microsoft.com/en-us/library/ms680747(VS.85).aspx)

    I would have expected an OUT int argument to accept dwRegister.

    According to the MSDN documentation, the interop version of Register method returns an HRESULT to indicate success or failure, not the ROT entry value I need. And it also says to refer to the existing documentation, which isn't very helpful here since the parameter is missing from the method signature.

    Anyone know how to get dwRegister?

    Thanks!

    Simon
    Sunday, December 21, 2008 7:56 PM

Answers

  • Documentation bug.  The IRunningObjectTable::Register() method in ComTypes is not declared with [PreserveSig].  So the return value is *not* the HRESULT, it is the pdwRegister argument value.   The one you need to pass to Revoke().
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, December 26, 2008 8:54 AM
    Sunday, December 21, 2008 8:57 PM
    Moderator