有关汇编中 win32 api 的帮助

发布于 2024-08-20 00:17:32 字数 1287 浏览 9 评论 0原文

为什么汇编中的结构声明与 win32 api 文档中的不同。(我来自 C++,正在尝试汇编语言)

例如,我从icezelion 的教程(tutorial3)中得到了这个函数原型

WNDCLASSEX STRUCT DWORD
  cbSize            DWORD      ?
  style             DWORD      ?
  lpfnWndProc       DWORD      ?
  cbClsExtra        DWORD      ?
  cbWndExtra        DWORD      ?
  hInstance         DWORD      ?
  hIcon             DWORD      ?
  hCursor           DWORD      ?
  hbrBackground     DWORD      ?
  lpszMenuName      DWORD      ?
  lpszClassName     DWORD      ?
  hIconSm           DWORD      ?
WNDCLASSEX ENDS   

嘿等等...我知道“WNDCLASSEX”结构,在我的离线版本的 win32 api 文档中,其声明为...

typedef struct _WNDCLASSEX {    // wc  
    UINT    cbSize; 
    UINT    style; 
    WNDPROC lpfnWndProc; 
    int     cbClsExtra; 
    int     cbWndExtra; 
    HANDLE  hInstance; 
    HICON   hIcon; 
    HCURSOR hCursor; 
    HBRUSH  hbrBackground; 
    LPCTSTR lpszMenuName; 
    LPCTSTR lpszClassName; 
    HICON   hIconSm; 
} WNDCLASSEX; 

为什么 asm 版本使用 DWORD 与 win32 api 文档中的内容相反?
我使用了错误的文档还是什么?如果我是的话,有人可以给我发一个供 asm 程序员使用的 WIN32 api 文档的下载链接吗?
求助,我很困惑。

已编辑:这是我参考的教程的链接:

iczelion 的 win32 asm教程3

why are the structure declarations in assembly different from those in the win32 api documentation.(i am coming from c++ and trying my hand at assembly language)

for example i got this function prototype from icezelion's tutorials(tutorial3)

WNDCLASSEX STRUCT DWORD
  cbSize            DWORD      ?
  style             DWORD      ?
  lpfnWndProc       DWORD      ?
  cbClsExtra        DWORD      ?
  cbWndExtra        DWORD      ?
  hInstance         DWORD      ?
  hIcon             DWORD      ?
  hCursor           DWORD      ?
  hbrBackground     DWORD      ?
  lpszMenuName      DWORD      ?
  lpszClassName     DWORD      ?
  hIconSm           DWORD      ?
WNDCLASSEX ENDS   

Hey wait...I know that "WNDCLASSEX" structure, in my offline version of the win32 api documentation, its declared as....

typedef struct _WNDCLASSEX {    // wc  
    UINT    cbSize; 
    UINT    style; 
    WNDPROC lpfnWndProc; 
    int     cbClsExtra; 
    int     cbWndExtra; 
    HANDLE  hInstance; 
    HICON   hIcon; 
    HCURSOR hCursor; 
    HBRUSH  hbrBackground; 
    LPCTSTR lpszMenuName; 
    LPCTSTR lpszClassName; 
    HICON   hIconSm; 
} WNDCLASSEX; 

Why is it that the asm version uses DWORD's only contrary to what is in the win32 api documentation?
Am i using the wrong docs or what? and if i am can someone post me a download link for WIN32 api documentation meant for asm programmers?
Help, am confused.

Edited: Here is the link to the tutorial i was refering to:

iczelion's win32 asm tutorial 3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

不气馁 2024-08-27 00:17:32

DWORDS 是 32 位 Windows 上的 32 位类型,该结构的 C 版本中的所有类型也是如此。因此两者是兼容的。

DWORDS are a 32-bit type on 32-bit windows, as are all the types in the C version of the structure. The two are therefore compatible.

疧_╮線 2024-08-27 00:17:32

汇编语言是无类型的 - DWORD 和其他关键字仅指示应为特定实体保留的字节数。事实上,由于 DWORD 及其表兄弟不代表操作码/助记符,因此它们实际上是宏预处理器的功能。

C/C++ 类型与其他语言的类型一样,受到字节顺序、符号位的位置、可能的强制转换、转换和赋值等规则的限制。您提供的结构的 C 版本比汇编语言版本,但兼容。

Assembly language is typeless - DWORD and other keywords merely indicate the number of bytes that should be reserved for a specific entity. In fact, since DWORD and its cousins do not represent opcodes/mnemonics, they are really features of the macro preprocessor.

C/C++ types, like those of other languages, are constrained by rules such as endian-ness, where the sign bit goes, what casts, converts and assignments are possible, etc. The C version of the structure you provided is more specific than the assembly language version, but is compatible.

等往事风中吹 2024-08-27 00:17:32

所有这些不同的 C 类型的大小都是 DWORD。程序集不是强类型的 - 它只知道每个变量的字节数。

The size of all those different C types is DWORD. Assembly is NOT strongly typed - all it knows about each variable is the number of bytes.

失而复得 2024-08-27 00:17:32

曾经(16 位 Windows)这些类型具有不同的大小。在迁移到 Win32 的过程中,它们最终都变成了 32 位数据类型。因此,DWORD 至少在某种程度上与所有这些兼容。

然而,与流行的看法相反,汇编语言确实(或至少可以)具有类型,甚至相当公平的类型安全性。举例来说,考虑一下当您执行以下操作时会发生什么:

mov lpszMenuName[ecx], 0

lpszMenuName 定义为 DWORD,汇编器不会接受此操作,因为“0”可能是byteworddword 或(在 64 位世界中)qword。为了使它工作,你必须添加(本质上)一个类型转换:

mov byte ptr lpszMenuName[ecx], 0

这样汇编器就知道你想写一个字节。或者,您可以将 lpszMenuName 定义为:

lpszMenuName ptr byte

在这种情况下,汇编器将知道它应该将其视为指向一个字节,而无需每次都明确声明。

At one time (16-bit Windows) these types had different sizes. During the migration to Win32, they all ended up as 32-bit data types. As such, a DWORD is compatible with all of them, to at least some degree.

Contrary to popular belief, however, assembly language does (or at least can) have types and even pretty fair type safety. Just for example, consider what happens when you do something like:

mov lpszMenuName[ecx], 0

With lpszMenuName defined as a DWORD, the assembler won't accept this, because the '0' could be a byte, a word, a dword or (in a 64-bit world) a qword. To make it work, you have to add (essentially) a type cast:

mov byte ptr lpszMenuName[ecx], 0

So the assembler knows you want to write a single byte. Alternatively, you can define lpszMenuName as:

lpszMenuName ptr byte

In which case, the assembler will know it should treat it as pointing at a byte without explicitly stating that each time.

与往事干杯 2024-08-27 00:17:32

WNDPROC、UINT 等是在 C 头文件中定义的,因此没有直接的 ASM 等效项。它们在 32 位系统上都是 DWORD 大小的数量,这就是该教程生成工作代码的原因。

WNDPROC, UINT, etc., are defined in the C headers, so there is no direct ASM equivilent. They are all DWORD sized quantities on 32-bit systems, which is why that tutorial produces working code.

夏天碎花小短裙 2024-08-27 00:17:32

在汇编中,无论高级结构是否具有指针或整数,实际情况是它们关联的高级数据类型是 BYTE、WORD 和 DWORD,在您的情况下,结构都是 32 位,因此 DWORD (一个 WORD 是 16 位,DWORD为32位)。不要误以为汇编中的结构与 C 中的结构不同,它们非常相似。汇编器具有原始数据类型,无论指针、结构等如何,它们的区别在于它如何加载到寄存器中(取决于语法):

mov eax, dword ptr [bx]

此汇编器示例演示了加载 eax 寄存器使用 bx 寄存器指向的值,实际上与

int bx = 5;
int *eax;
ptr = &bx;

希望这有帮助,
此致,
汤姆.

In assembly, regardless of whether a high level structure has pointers or ints, the reality is that their associated high-level datatypes are of BYTE, WORD and DWORD, in your case, the structure are all 32 bit hence DWORD (a WORD is 16bit, DWORD is 32bits). Do not be mislead into thinking the structure in assembly is different to the structure in C, it is very much the same. Assembler has primitive data types, regardless of pointers, structures etc, what sets them apart is how it is loaded into a register (depending on the syntax):

mov eax, dword ptr [bx]

This assembler sample is a demonstration of loading the eax register with the value pointed to by the bx register, effectively same thing as

int bx = 5;
int *eax;
ptr = &bx;

Hope this helps,
Best regards,
Tom.

人事已非 2024-08-27 00:17:32

事实上,MASM 6+ 支持某种形式的类型,因此您可以在 MASM 中拥有类似于 C 中的结构。但是您必须首先重新创建类型层次结构,并且您很快就会注意到以下好处:使用 MASM 打字在某种程度上是有限的(曾经在那里,做过那件事)。我建议您谷歌一下 MASM 6 程序员参考 PDF 文件:它相当清楚地解释了 MASM 中的“HLL”优点,包括打字,并包含许多示例。
下面的链接似乎提供了一份副本,但还有其他版本。

http://www.microlab.teipat.gr/upload/arxeshy/Microsoft_MASM_Programmers_Guide_v6。邮编

In fact, MASM 6+ supports a form of typing, so you could have your structure in MASM similar to the one you have in C. But you would have to recreate the type hierarchy first, and you'd soon notice that the benefits of typing with MASM are somehow limited (been there, done that). I suggest you Google the MASM 6 Programmer's Reference PDF file: It rather clearly explains of the "HLL" goodies in MASM, including typing, and includes a number of examples.
One copy seems to be available at the link below, but there are others floating around.

http://www.microlab.teipat.gr/upload/arxeshy/Microsoft_MASM_Programmers_Guide_v6.zip

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文