A few caveats apply to certain combinations of directional attributes and pointer attributes.
When you use out-only reference pointers in Microsoft RPC, the generated server stubs allocate only the first level of pointers accessible from the reference pointer. Pointers at deeper levels are not allocated by the stubs, but must be allocated by the server application layer.
For example, consider an out-only array of reference pointers:
/* IDL file (fragment) */
typedef [ref] short * PREF;
Proc1([out] PREF array[10]);
In the preceding example, the server stub allocates memory for ten pointers and sets the value of each pointer to null. The server application must allocate the memory for the ten short integers that are referenced by the pointers and must set the ten pointers to point to the integers.
When the out-only data structure includes nested reference pointers, the server stubs allocate only the first pointer accessible from the reference pointer. For example:
/* IDL file (fragment) */
typedef struct {
[ref] small * psValue;
} STRUCT1_TYPE;
typedef struct {
[ref] STRUCT1_TYPE * ps1;
} STRUCT_TOP_TYPE;
Proc2([out, ref] STRUCT_TOP_TYPE * psTop);
In the preceding example, the server stubs allocate the pointer psTop and the structure STRUCT_TOP_TYPE. The reference pointer ps1 in STRUCT_TOP_TYPE is set to null. The server stub does not allocate every level of the data structure, nor does it allocate the STRUCT1_TYPE or its embedded pointer, psValue.
Out-only unique or full pointers are not accepted by the MIDL compiler. Such specifications cause the MIDL compiler to generate an error message.
The automatically generated server stub has to allocate memory for the pointer referent so the server application can store data in that memory area. According to the definition of an out-only parameter, no information about the parameter is transmitted from client to server. In the case of a unique pointer, which can take the value NULL, the server stub does not have enough information to correctly duplicate the unique pointer in the server's address space, nor does the stub have any information about whether the pointer should point to a valid address or whether it should be set to NULL. Therefore, this combination is not allowed.
Rather than out, unique or out, ptr pointers, use in, out, unique or in, out, ptr pointers, or use another level of indirection such as a reference pointer that points to the valid unique or full pointer.