大网数据广告活动
网络与域名解析

Default Pointer Types

· 52CE 我爱测

Pointers are not required to have an explicit attribute description. When an explicit attribute is not provided, the MIDL Compiler uses a default pointer attribute.

Pointers are not required to have an explicit attribute description. When an explicit attribute is not provided, the MIDL Compiler uses a default pointer attribute.

The default cases for unattributed pointers are the following:

  • Top-level pointers that appear in parameter lists default to [ref] pointers.
  • All other pointers default to the type specified by the [pointer_default] attribute. When no [pointer_default] attribute is supplied, these pointers default to the [ unique ] attribute when the MIDL compiler is in Microsoft Extensions mode or the [ptr] attribute when the MIDL compiler is in DCE-compatible mode.

When a remote procedure returns a pointer, the return value must be a [ unique ] or full ([ ptr ]) pointer.

/* 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.    
}

Remarks

To ensure unambiguous pointer-attribute behavior, always use explicit pointer attributes when defining a pointer.

It is recommended that [ptr] is used only when pointer aliasing is required.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。