在VBA中正确声明DWord
我使用的API函数返回一个在VBA中正确声明DWord,vba,winapi,integer,long-integer,Vba,Winapi,Integer,Long Integer,我使用的API函数返回一个DWORD 因为我希望在LoWord和HiWord上使用intellisense,而不是使用Long: Declare Sub myAPI(ByRef outVariable As Long) …正如WinAPI->VBA数据类型转换中的建议,我使用的是一种类型: Public Type DWORD 'same size as Long, but intellisense on members is nice '@Ignore IntegerDataType
DWORD
因为我希望在LoWord
和HiWord
上使用intellisense,而不是使用Long
:
Declare Sub myAPI(ByRef outVariable As Long)
…正如WinAPI->VBA数据类型转换中的建议,我使用的是一种类型:
Public Type DWORD 'same size as Long, but intellisense on members is nice
'@Ignore IntegerDataType
LoWord As Integer
'@Ignore IntegerDataType
HiWord As Integer
End Type
Declare Sub myAPI(ByRef outVariable As DWORD)
然而,RubberDuck的检查提醒我,在32位系统上,我想知道我的DWORD声明是否真的像预期的那样是4个连续字节,还是8个
我对指针和位字节不够熟悉,无法在脑海中描绘出正在发生的事情,但我想象API不知何故只知道填充每个部分的下半部分,因为我已经从API中得到了我期望的结果。您的用户定义类型是4字节大小,因为
Integer
是2字节大小
您可以自己检查:
Dim dw as DWORD
Dim size as Integer
size = LenB(dw)
最近的讨论:根据上面链接中的GSerg,整个“整数存储为长”事实上可能是错误的,即使它写在您的SO链接中引用的MS文档中()