默认指针类型
不需要指针具有显式属性说明。 如果未提供显式属性,MIDL 编译器将使用默认指针属性。
未指定的指针的默认情况如下:
- 参数列表中出现的顶级指针默认为 [ref] 指针。
- 所有其他指针默认为 [pointer_default] 属性指定的类型。 如果未提供 [pointer_default] 属性,则当 MIDL 编译器处于与 DCE 兼容的模式下时,这些指针默认为 [唯一的 ] 属性 Microsoft扩展 模式或 [ptr] 属性。
当远程过程返回指针时,返回值必须是 [唯一 ] 或 full ([ ptr ]) 指针。
/* IDL file compiled without /osf */
[
uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45),
version(1.0),
pointer_default(ptr)
]
interface MyInterface
{
typedef long *PLONG;
struct MyCircularList {
struct MyCircularList *pRight;
struct MyCircularList *pLeft;
long Data;
};
void Foo1( [in] PLONG p ); // p is ref
void Foo2( [in] struct MyCircularList *p ); // p is ref, p->pRight and p->pLeft is ptr
struct MyCircularList *Foo3( void ); // returned pointer is ptr.
}
[
uuid(ba209999-0c6c-11d2-97cf-00c04f8eea46),
version(1.0)
]
interface MyInterface2
{
struct MySingleList
{
struct MySingleList *pNext;
long Data;
};
void Foo4( [in] struct MySingleList *p ); // p is ref, p->pNext is unique
struct MySingleList *Foo5( void ); // returned pointer is unique.
}
言论
为了确保明确的指针属性行为,请始终在定义指针时使用显式指针属性。
建议仅在需要指针别名时才使用 [ptr]。