3.1.1.5.1 Marshaling an Object
The object exporter MUST perform the following operations to marshal an object into an OBJREF of OBJREF_STANDARD type when returning from an ORPC. In this case, the application or higher-layer protocol MUST supply an object pointer and an IID; see section 4.5.
The object exporter MUST look up the OID entry in the OID table using the object pointer.
If the OID entry is not found, the object exporter MUST create an entry as follows:
The object exporter MUST contact the object resolver to allocate an OID and set it in the OID entry.
The object exporter MUST initialize the IPID list in the OID entry to NULL.
The object exporter MUST set the object pointer in the OID entry to the object pointer supplied by the application.
The object exporter MUST look up the IPID entry in the IPID list of the OID entry using the IID specified by the application:
If the IPID entry is not found, the object exporter MUST create an IPID entry as follows:
The object exporter MUST allocate an IPID and set it in the IPID entry.
The object exporter MUST set the OID in the IPID entry to the OID obtained from the object resolver.
The object exporter MUST set the OXID in the IPID entry to the OXID of the object exporter.
The object exporter MUST set the IID in the IPID entry to the IID specified by the application; see section 4.5.
The object exporter MUST set the public reference count in the IPID entry to an initial value. The initial value MUST be 0 or more and SHOULD be 5.
The object exporter MUST set the private reference count to 0.
The object exporter MUST instruct RPC to listen on the interface designated by the IID, as specified in [C706] section 3.1.20 (rpc_server_register_if).
Set the object pointer in the IPID entry to the object pointer of the application's state that implements the interface specified by the IID. The application state is implementation-specific.
The object exporter MUST add the IPID to the IPID list of the OID entry.
Otherwise, the object exporter MUST increment the public reference count in the IPID entry by the initial value.
The object exporter MUST set the last ORPC invocation time in the OID entry to the current time.
The object exporter MUST construct a STDOBJREF instance for the object as follows:
The object exporter SHOULD set the flags field to 0.<39>
The object exporter MUST set cPublicRefs to the initial value.
The object exporter MUST set the IPID and the OID from the respective IPID and OID entries.
The object exporter MUST set the OXID to the OXID of the object exporter.
The object exporter MUST create an OBJREF_STANDARD instance as follows:
The object exporter MUST set the std field to the constructed STDOBJREF instance.
The object exporter MUST set the saResAddr field to the DUALSTRING array of the object resolver.
The object exporter MUST create an OBJREF instance as follows:
The object exporter MUST set the signature field to 0x574f454d.
The object exporter MUST set the flags field to OBJREF_STANDARD.
The object exporter MUST set the iid field to the IID supplied by the application.
The object exporter MUST set the u_objref field to the OBJREF_STANDARD instance.
The object exporter MUST use NDR to marshal the OBJREF into an MInterfacePointer that is placed in the RPC PDU body.
Applications or higher-layer protocols can also instruct the object exporter to marshal OBJREF instances of type OBJREF_HANDLER, OBJREF_EXTENDED, and OBJREF_CUSTOM. In this case, the object exporter MUST create an OBJREF, as specified previously, with the exception that it MUST set the flags field to the corresponding flag type of the OBJREF, and the u_objref field to the corresponding OBJREF instance.
An application or higher-layer protocol can instruct the object exporter to return envoy context properties when marshaling an object. In this case, the object exporter MUST create an OBJREF_EXTENDED structure (see section 2.2.18.7) with an ElmArray (see section 2.2.18.8) whose Data field contains a Context structure (see section 2.2.20). The object exporter MUST create the Context structure as follows:
It MUST set the Count field of the Context structure to the number of envoy context properties supplied by the application or higher-layer protocol.
For each envoy context property, it MUST create a PropMarshalHeader array element as follows:
It MUST set the clsid field to the CLSID supplied by the application or higher-layer protocol.
It MUST set the policyId field to the context property identifier supplied by the application or higher layer protocol.
It MUST set the flags field to CPFLAG_ENVOY.
It MUST set the cb field to the size of the buffer supplied by the application or the higher-layer protocol.
It MUST set the ctxPropery field to the buffer supplied by the application or higher-layer protocol.