Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBA中正确声明DWord_Vba_Winapi_Integer_Long Integer - Fatal编程技术网

在VBA中正确声明DWord

在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

我使用的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
    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文档中()