Windows API 声明中数据类型上的星号是什么?
我知道(例如)DWORD
是什么,它是一个四字节无符号长整数。
但是参数名称前带有星号的 DWORD *
是什么意思,如下所示:
HRESULT UrlUnescape(
__inout PTSTR pszURL,
__out_opt PTSTR pszUnescaped,
__inout_opt DWORD *pcchUnescaped,
DWORD dwFlags
);
UPDATE
我突然想到我有一些额外的提示,表明它是一个指针。第一个是参数名称以 p 开头。另一个是它是一个输入/输出参数,被调用者可以更改调用者变量值的唯一方法是传递指针而不是值。当然,字符串也是指针,并且它们不使用星号,但那是因为字符串不能按值传递,所以它会是多余的,而整数肯定可以传递按价值(并且经常/通常是)。
I know what (for example) a DWORD
is, it's a four-byte unsigned long integer.
But what does DWORD *
with an asterisk before the parameter name mean, as seen here:
HRESULT UrlUnescape(
__inout PTSTR pszURL,
__out_opt PTSTR pszUnescaped,
__inout_opt DWORD *pcchUnescaped,
DWORD dwFlags
);
UPDATE
It occurs to me I had a few additional hints that it was a pointer. The first is that the parameter name starts with a p. The other is that it is an in/out parameter, and the only way the callee could alter the value of the caller's variable is if a pointer is passed rather than a value. Of course, the strings are pointers too, and they don't use the asterisk, but that's because a string can't be passed by value so it would be redundant, while an integer certainly can be passed by value (and often/usually is).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着 pcchUnescaped 是指向 DWORD 类型对象的指针。这是普通的 C 语言,与 Windows API 没有任何具体关系。
It means that
pcchUnescaped
is pointer to an object of typeDWORD
. That's normal C, nothing specifically related to the Windows API.它表示指向内存中
DWORD
的指针。It means a pointer to a
DWORD
in the memory.来自 MSDN:
DWORD 是 32 位无符号整数(范围:十进制 0 到 4294967295)。由于 DWORD 是无符号的,因此其第一位(最高有效位 (MSB))不会保留用于签名。
From MSDN:
A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal). Because a DWORD is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing.