none
Using Windows Libraries with VBA (Declare Function, etc) - Best Resources? RRS feed

  • Question

  • So far I've been piecing little bits of information from various sources to try and understand how to use VBA & things like Windows Messages.  Since most of that is written in C++, (I know C#, but not C or C++), I have to find examples of people using these functions in VBA in order to use them myself.

    Is there a useful guide that can help me figure out some of the questions I have?  It seems that the VBA documentation is lacking in this respect, although it has one example.

    For example, what does "X as Any" mean when declaring parameters?  Is it the same as Variant?

    In some functions declared for 64-bit Excel, I see the return type as Long, but shouldn't this always be LongPtr?

    I see this in the docs a lot, and am not totally sure what it means: "The atom must be in the low-order word of lpClassName; the high-order word must be zero."  That is from the CreateWindowExA function, but it appears in other functions too.

    What documentation should I be reading?  I've gone through all of the functions and such listed under Winuser.h, but there's a lot more out there.

    Thanks for any help.  No need to answer all my questions, just whatever you know!

    Sunday, May 26, 2019 3:58 PM

All replies

  • I'm not sure there is a single source of information that covers your questions as they fall under different aspects of computing, briefly -

    "X as Any"
    It means the data type is not checked, so any data type being passed will compile. Functions which can accept 'Any' typically process the received value in different ways depending on its data type. It is not the same as As Variant, the received 'data type' will remain the same as passed. If you know you will always pass say a Long you can change the As Any to As Long.

    "LongPtr"
    LongPtr is a Long in 32bit and a LongLong in x64. In x64 pointers and handles are LongLong, ie 64bit values, and if that's what the the function returns should be declared as LongPtr (in exclusively x64 bit or under #IF Win64 can be declared as LongLong). Same goes for other relevant arguments within the function, not just returns, also variables in the rest of code should be declared appropriately to match. Many APIs in x64 return Longs, and if so should be declared to return As Long, even in x64

    "Atom"
    https://docs.microsoft.com/en-us/windows/desktop/dataxchg/about-atom-tables

    "high word low word"
    consider this 32bit Long and its constituent High/Low 16bit words
    Debug.Print &H10002000, &H1000, &H2000

    Monday, May 27, 2019 10:14 AM
    Moderator