public int RegisterObject(object obj, string stringId) { int regId = -1; System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT = null; System.Runtime.InteropServices.ComTypes.IMoniker pMoniker = null; int hr; if ((hr = NativeMethods.GetRunningObjectTable((uint)0, out pROT)) != 0) { return(hr); } // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT if ((hr = NativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0) { return(hr); } regId = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker); _RegisteredObjects.Add(new ObjectInRot(obj, regId)); return(0); }
/// <summary> /// This allows us to register an object in the Running Object Table /// </summary> /// <param name="obj">A Com interface pointer owned by the object</param> /// <param name="stringId">A display name for the object</param> /// <returns>Returns two integers as an array, the first is the HRESULT of system calls and if successful the second is the registration id (regid). You'll need the regid to revoke from the ROT when tidying up.</returns> public int[] RegisterObject(object obj, string stringId) { int[] retval = new int[] { 0, 0 }; int regId = -1; System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT = null; System.Runtime.InteropServices.ComTypes.IMoniker pMoniker = null; int hr; if ((hr = RotNativeMethods.GetRunningObjectTable((int)0, out pROT)) != 0) { retval[0] = hr; return(retval); //(hr); } // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT if ((hr = RotNativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0) { retval[0] = hr; return(retval); //(hr); } int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1; regId = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker); retval[0] = 0; retval[1] = regId; return(retval); }
private static extern int GetRunningObjectTable(uint reserved, out System.Runtime.InteropServices.ComTypes.IRunningObjectTable pprot);
private static extern Int32 GetRunningObjectTable(UInt32 reserved, out comTypes.IRunningObjectTable rot);