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

Reference Pointers

· 52CE 我爱测

Reference pointers are the simplest pointers and require the least amount of processing by the client stub.

Reference pointers are the simplest pointers and require the least amount of processing by the client stub. When a client program passes a reference pointer to a remote procedure, the reference pointer always contains the address of a valid block of memory. It will still be pointing to the same memory block when the remote procedure completes. These pointers are mainly used to implement reference semantics, and to allow for [out] parameters in C.

In the following example, the value of the pointer does not change during the call, although the contents of the data at the address indicated by the pointer can change.

data changing at a static reference pointer address

A reference pointer has the following characteristics:

  • It always points to valid storage and never has the value NULL.
  • It never changes during a call and always points to the same storage before and after the call.
  • Data returned from the remote procedure is written into the existing storage.
  • The storage pointed to by a reference pointer cannot be accessed by any other pointer or any other name in the function.

Use the [ref] attribute to specify reference pointers in interface definitions, as shown in the following example.

/* IDL file */
[ 
  uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45),
  version(1.0)
]
interface RefPtrInterface
{
  void RemoteFn([in, out, ref] char *pChar);
}

This example defines the parameter pChar as a pointer to a single character, not an array of characters. It is an [out] parameter and a reference pointer that points to memory that the server routine RemoteFn will fill with data.

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)

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

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