gpt4 book ai didi

delphi - 为什么 PDWord 不是 ^DWORD?

转载 作者:行者123 更新时间:2023-12-03 14:33:48 25 4
gpt4 key购买 nike

这个程序

{$APPTYPE CONSOLE}
{$TYPEDADDRESS ON}

uses
Winapi.Windows;

procedure Foo(P: PDWORD);
begin
end;

procedure Bar;
var
dw: DWORD;
begin
Foo(@dw);
end;

begin
end.

在 XE3 中编译,但在 XE4、XE5、XE6 和 XE7 中不编译。错误位于

Foo(@dw);
[dcc32 Error] E2010 Incompatible types: 'PDWORD' and 'Pointer'

This feels odd. So, after a bit of digging it seems that the issue is down to the definition of PDWORD. One might naturally think that it would be:

PDWORD = ^DWORD;

XE3 中确实就是这种情况。在以后的版本中我们发现:

// Note: Not ^DWORD yet
PDWORD = ^CppULongInt;

奇怪。那么,什么是CppULongInt

CppULongInt = type LongWord; 
{$EXTERNALSYM CppULongInt 'unsigned long'}
{$OBJTYPENAME CppULongInt 'Bul' 'Gm'}

然后查看 DWORD 的声明,我们发现:

//NOTE: DWORD should really be CppULongInt
DWORD = LongWord;

因此,CppULongIntDWORD 是不同的类型。因此出现编译错误。

这是怎么回事? CppULongInt 的用途是什么?为什么 RTL 设计者似乎想要将 DWORD 别名为 CppULongInt。此更改与基于 LLVM 的 x64 Windows C++ 编译器有关吗?我是世界上唯一使用 {$TYPEDADDRESS ON} 的人吗?

请注意,最后一个问题是反问句。

最佳答案

(指Why PDWORD is not a pointer to DWORD。)看起来内河码头有人没有读过the relevant Windows documentation。 :

  • DWORD 被显式定义为 32无符号整数,因此在 Delphi 中它应该是 UInt32 .
  • PDWORD 被定义为指向 DWORD 的指针,因此在 Delphi 中它应该是 PDWORD = ^DWORD
  • DWORD_PTR(不是 PDWORD!)被定义为 ULONG_PTR,后者的大小会根据平台(32 或 64 位),而不是 unsigned long 的编译器定义。

原因之一可能是他们试图在非 Windows 平台上使用 DWORD 和其他 Windows 数据类型,并试图保持它们的兼容性。如果是这样,在这种情况下他们会失败并引入错误,因为使用的定义在 Windows 中无法正常工作。

关于delphi - 为什么 PDWord 不是 ^DWORD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25817360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com