0

I'm using an API function which returns a DWORD

Because I want intellisense on the LoWord and HiWord, rather than using a Long:

Declare Sub myAPI(ByRef outVariable As Long)

...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)

However RubberDuck's IntegerDataType inspection reminded me that on 32 bit systems VBA converts 2-byte Integers to 4-byte Longs internally, so I'm wondering whether my DWORD declaration is really 4 consecutive bytes as expected, or 8.

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.

Greedo
  • 4,967
  • 2
  • 30
  • 78
  • More recent discussion: https://stackoverflow.com/questions/26717148/integer-vs-long-confusion – L8n Sep 11 '19 at 15:32
  • According to GSerg in the link above the whole "Integer is stored as Long" thing may actually be wrong, even though it is written in the MS Docs that is referenced in your SO-Link (https://learn.microsoft.com/en-us/previous-versions/office/developer/office2000/aa164506(v=office.10)?redirectedfrom=MSDN) – L8n Sep 11 '19 at 15:54

1 Answers1

0

Your user defined type is 4 bytes is size, because Integer is 2 bytes in size.

You can check this for yourself:

Dim dw as DWORD
Dim size as Integer
size = LenB(dw)
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490