Hi,
It's a COM trick :) A _physical_ return value of the Register method *is* an
HRESULT. Here's the raw definition:
HRESULT Register(DWORD grfFlags, IUnknown * punkObject, IMoniker *
pmkObjectName, DWORD * pdwRegister);
As you can see, the cookie is physically the last output parameter.
However, in the .NET world, the Interop layer makes things simplier for you.
It hides the HRESULT and pretends that the cookie is *the* return value.
Should the returned HRESULT indicate failure, the Interop layer throws an
exception that, in particular, contains the actual HRESULT value.
Still with me? :) Feel free to follow up, I know it's not a straightforward
topic.
--
Regards,
Dmytro Lapshyn [MVP]
http://blogs.vbcity.com/DmytroL [quoted text, click to view] "lgs.lgs" <limegreensocks@nospam.yahoo.com> wrote in message
news:OghBHJRsGHA.4872@TK2MSFTNGP02.phx.gbl...
> Could someone take a look at the docs for this method?
>
>
http://windowssdk.msdn.microsoft.com/en-us/library/system.runtime.interopservices.comtypes.irunningobjecttable.register.aspx
>
> In particular, I'm interested in the return value. The docs say it is an
> HRESULT. However, I sincerely doubt this. If I'm not mistaken, what it
> is
> actually returning is the cookie needed to do the
> IRunningObjectTable.Revoke.
>
> When you think about it, if there were an error, wouldn't you expect an
> exception rather than an HRESULT?
>
> However, I'm not 100% certain, and a double-check would be appreciated.
>
>
>
[quoted text, click to view] > It's a COM trick :)
Thanks for the response.
Yes, I am familiar with the [PreserveSig] trick. And in general, this is a
good thing in .NET. However, since IRunningObjectTable is compiled code, I
can't change its behavior. So, this tells me that it will NOT, under any
circumstances, return an HRESULT to my c# code.
However, the docs which describe using this method specifically say that the
return value *is* an HRESULT. And they *don't* make any reference at all to
a cookie (which is essential to using ROT).
In short then, the docs are simply wrong. Which is what I suspected.