DWORD int

本文解释了int和DWORD在C++编程中的区别,特别是在Windows环境下。int是一个有符号整型,其大小随机器位数变化;而DWORD是一个无符号长整型,定义在windows.h中,固定为32位。此外,还提供了不同数据类型大小的实际示例。
int是有符号的,而DWORD是无符号的

typedef unsigned long DWORD;


DWORD 32位 不是c++类型,它定义在windows.h中

int会随着机器位数的不同而发生变化,比如在16位机上为16为,在32位机上为32位,在64位机上为64位


建议在DWORD的地方尽量使用DWORD.


int 与 long的区别在这儿:[url=http://stackoverflow.com/questions/271076/what-is-the-difference-between-an-int-and-a-long-in-c/271132#271132]http://stackoverflow.com/questions/271076/what-is-the-difference-between-an-int-and-a-long-in-c/271132#271132[/url]


printf("%d", sizeof(char));
printf("%d", sizeof(short));
printf("%d", sizeof(int));
printf("%d", sizeof(DWORD));
printf("%d", sizeof(long));



在win7 64, VS 2005中,上面输出12444
#include "apdefap.h" int _main(void) { /* 读现场变量 */ DWORD op1 = GetTagDWord("Unit_Operation_Code_Chiller1"); DWORD saf1 = GetTagDWord("Unit_Safety_Fault_Code_Chiller1"); DWORD cyc1 = GetTagDWord("Unit_Cycling_Fault_Code_Chiller1"); DWORD wrn1 = GetTagDWord("Unit_Warning_Code_Chiller1"); DWORD op3 = GetTagDWord("Unit_Operation_Code_Chiller3"); DWORD saf3 = GetTagDWord("Unit_Safety_Fault_Code_Chiller3"); DWORD cyc3 = GetTagDWord("Unit_Cycling_Fault_Code_Chiller3"); DWORD wrn3 = GetTagDWord("Unit_Warning_Code_Chiller3"); DWORD ctrl1 = GetTagDWord("Unit_Control_Source_Chiller1"); DWORD mod1 = GetTagDWord("Unit_Modified_Run_Code_Chiller1"); DWORD int1 = GetTagDWord("Unit_Internal_Fault_Code_Chiller1"); DWORD ctrl3 = GetTagDWord("Unit_Control_Source_Chiller3"); DWORD mod3 = GetTagDWord("Unit_Modified_Run_Code_Chiller3"); DWORD int3 = GetTagDWord("Unit_Internal_Fault_Code_Chiller3"); /* 统一消息号触发 */ DWORD i; for (i = 0; i <= 14; i++) SetMessage(1000 + i, op1 == i); for (i = 0; i <= 30; i++) SetMessage(2000 + i, saf1 == i); for (i = 0; i <= 14; i++) SetMessage(5000 + i, cyc1 == i); for (i = 0; i <= 19; i++) SetMessage(7000 + i, wrn1 == i); for (i = 0; i <= 14; i++) SetMessage(3000 + i, op3 == i); for (i = 0; i <= 30; i++) SetMessage(4000 + i, saf3 == i); for (i = 0; i <= 14; i++) SetMessage(6000 + i, cyc3 == i); for (i = 0; i <= 19; i++) SetMessage(8000 + i, wrn3 == i); for (i = 0; i <= 4; i++) SetMessage(9000 + i, ctrl1 == i); for (i = 0; i <= 5; i++) SetMessage(11000 + i, mod1 == i); for (i = 0; i <= 3; i++) SetMessage(13000 + i, int1 == i); for (i = 0; i <= 4; i++) SetMessage(10000 + i, ctrl3 == i); for (i = 0; i <= 5; i++) SetMessage(12000 + i, mod3 == i); for (i = 0; i <= 3; i++) SetMessage(14000 + i, int3 == i); return 0; }
最新发布
11-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值