This method of the IRunningObjectTable interface registers an object and its identifying moniker in the Running Object Table (ROT).
public void Register(int grfFlags, IUnknown punkObject, IMoniker pmkObjectName, int[] pdwRegister);
This method supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following:
S_OK -- The object was successfully registered.
MK_S_MONIKERALREADYREGISTERED -- The moniker/object pair was successfully registered, but that another object (possibly the same object) has already been registered with the same moniker.
[in] grfFlags | Specifies whether the ROT's reference to punkObject is weak or strong and controls access to the object through its entry in the ROT. (See the following remarks.) |
[in] punkObject | The pointer to the object that is being registered as running. |
[in] pmkObjectName | The pointer to the moniker that identifies punkObject. |
[out] pdwRegister | Pointer to a 32-bit value that can be used to identify this ROT entry in subsequent calls to Revoke or NoteChangeTime. The caller cannot specify NULL for this parameter. If an error occurs, pdwRegister is set to 0 (zero). |
This method registers a pointer to an object under a moniker that identifies the object. The moniker is used as the key when the table is searched with GetObject.
The grfFlags parameter accepts two flag settings:
When an object is registered, the ROT always calls AddRef on the object. For a weak registration (ROTFLAGS_REGISTRATIONKEEPSALIVE not set), the ROT will release the object whenever the last strong reference to the object is released. For a strong registration (ROTFLAGS_REGISTRATIONKEEPSALIVE set), the ROT prevents the object from being destroyed until the object's registration is explicitly revoked.
A server registered as either LocalService or RunAs can set the ROTFLAGS_ALLOWANYCLIENT flag in its call to Register to allow any client to connect to it. A server setting this bit must have its executable name in the AppID section of the registry that refers to the AppID for the executable. An "activate as activator" server (not registered as LocalService or RunAs) must not set this flag in its call to Register.
Registering a second object with the same moniker, or re-registering the same object with the same moniker, creates a second entry in the ROT. In this case, Register returns MK_S_MONIKERALREADYREGISTERED. Each call to Register must be matched by a call to Revoke because even duplicate entries have different pdwRegister identifiers. A problem with duplicate registrations is that there is no way to determine which object will be returned if the moniker is specified in a subsequent call to IsRunning.