在WinDef.h中有这样两组宏定义:
#define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
LOBYTE(w)的作用是,获取WORD的低位字节;HIBYTE(w)的作用,获取WORD的高位字节。
DWORD_PTR, 实际上是unsigned long类型的数据类型,但是它在windows操作系统中表示储存的是一个地址的整数形式,也可以储存DWORD的数值。 DWORD,实际上也是unsigned long类型的数据类型,也可以储存一个地址。
DWORD_PTR和DWORD差别:
//main.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//DWORD_PTR和DWORD都储存一个地址指针
int a = 200;
DWORD_PTR ptr = (DWORD_PTR)&a;
DWORD dw = (DWORD)&a;
cout.setf(ios_base::uppercase);
cout << &a << endl;
cout << setw(8) << setfill('0') << uppercase << hex << ptr << endl;
cout << setw(8) << setfill('0') << uppercase << hex << dw << endl;
cout << nouppercase << dec;
cout << 'a = ' << *(int *)ptr << endl;
cout << 'a = ' << *(int *)dw << endl;
//DWORD_PTR和DWORD都储存一个整型
int b = 100;
DWORD_PTR ptrb = b;
DWORD dwb = b;
cout << 'b = ' << ptrb << endl;
cout << 'b = ' << dwb << endl;
getchar();
return 0;
}
运行结果:
0032F63C
0032F63C
0032F63C
a = 200
a = 200
b = 100
b = 100
联系客服