public RunningObjectTableEntry(object iUnknownObject, string name)
{
int hresult;
const int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;
System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot = null;
System.Runtime.InteropServices.ComTypes.IMoniker moniker = null;
try
{
hresult = GetRunningObjectTable(0, out rot);
if (hresult < 0) throw new COMException("GetRunningObjectTable failed.", hresult);
string wsz = string.Format("{0} {1:x16} pid {2:x8}",
name,
Marshal.GetIUnknownForObject(iUnknownObject).ToInt64(),
System.Diagnostics.Process.GetCurrentProcess().Id);
hresult = CreateItemMoniker("!", wsz, out moniker);
if (hresult < 0) throw new COMException("CreateItemMoniker failed.", hresult);
int register = rot.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, iUnknownObject, moniker);
this.register = register;
}
finally
{
if (moniker != null) Marshal.ReleaseComObject(moniker);
if (rot != null) Marshal.ReleaseComObject(rot);
}
}