預設指標類型

不需要指標才能有明確的屬性描述。 未提供明確屬性時,MIDL 編譯器會使用預設指標屬性。

未設定指標的預設案例如下:

  • 出現在參數清單中的最上層指標預設為 [ref] 指標。
  • 所有其他指標都會預設為 [pointer_default] 屬性所指定的類型。 當未提供 [pointer_default] 屬性時,當 MIDL 編譯器處於Microsoft Extensions模式或 [ptr] 屬性處於 DCE 相容模式時,這些指標預設為 [一 ] 屬性。

當遠端程式傳回指標時,傳回值必須是 [ unique ] 或 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]。