在VBA中正确声明DWord [英] Correct declaration of DWord in VBA
问题描述
我正在使用API函数,该函数返回DWORD
I'm using an API function which returns a DWORD
因为我想在LoWord
和HiWord
上使用智能,而不是使用Long
:
Because I want intellisense on the LoWord
and HiWord
, rather than using a Long
:
Declare Sub myAPI(ByRef outVariable As Long)
...如WinAPI的此列表-> VBA数据类型转换中所建议的,我正在使用一种类型:
...as suggested in this list of WinAPI -> VBA datatype conversions, I'm using a type:
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的 IntegerDataType 检查提醒我在32位系统上
However RubberDuck's IntegerDataType inspection reminded me that on 32 bit systems VBA converts 2-byte Integer
s to 4-byte Long
s internally, so I'm wondering whether my DWORD declaration is really 4 consecutive bytes as expected, or 8.
我对指针和位&不够熟悉.字节在脑海中描绘出了什么情况,但是我想API某种程度上只知道填充每个部分的下半部分,因为我一直在从API中获得我期望的结果(我认为).
I'm not familiar enough with pointers and bits & bytes to picture in my head what's going on, but I imagine the API somehow knows to fill only the lower half of each part, as I've been getting the results I expect (I think) from the API.
推荐答案
您定义的类型为4个字节,因为Integer
为2个字节.
Your user defined type is 4 bytes is size, because Integer
is 2 bytes in size.
您可以自己检查:
Dim dw as DWORD
Dim size as Integer
size = LenB(dw)
这篇关于在VBA中正确声明DWord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!