VBA C++ type equivalences

Some template and type conversions equivalences from C++
'    [Public | Private] Declare Function publicname Lib "libname" _
    [Alias "alias"] [([[ByVal | ByRef] argument [As Type] _
    [, [Byval | ByRef] argument [As Type]] ...])] [As Type]

'Overview of the Declare Statement
'    [Public | Private] Declare [Ansi | Unicode | Auto] Sub | _
    Function <name> Lib "<library"> [Alias "<alias>"] [([argument list])]

'Data Types (As Type)
'
'The functions that make up the Windows API are written in C. Here are some of the most common data types you will encounter when using the API.
'
'    Integer: Used for 16-bit numeric arguments.
'    Equivalent to the short, unsigned short and WORD data types in C
'    Long: Used for 32-bit arguments.
'    Corresponds to the C data types: int, unsigned int, unsigned long, DWORD, and LONG.
'    String: Equivalent C Data type is LPSTR
'    Structure: A Structure is the C++ equivalent to a Visual Basic UDT (User Defined Type)
'    Any: Some functions accept more than one data type for the same argument
'
'A short table that helps you translate the C++ variable type declaration to its equivalent in Visual Basic:
' C++ Variable    Visual Basic Equivalent
' ATOM          ByVal variable as Integer
' BOOL          ByVal variable as Long
' BYTE          ByVal variable as Byte
' CHAR          ByVal variable as Byte
' COLORREF      ByVal variable as Long
' DWORD         ByVal variable as Long
' HWND          ByVal variable as Long
' HDC           ByVal variable as Long
' HMENU         ByVal variable as Long
' INT           ByVal variable as Long
' UINT          ByVal variable as Long
' LONG          ByVal variable as Long
' LPARAM        ByVal variable as Long
' LPDWORD       variable as Long
' LPINT         variable as Long
' LPUINT        variable as Long
' LPRECT        variable as Type any variable of that User Type
' LPSTR         ByVal variable as String
' LPCSTR        ByVal variable as String
' LPVOID        variable As Any use ByVal when passing a string
' LPWORD        variable as Integer
' LPRESULT      ByVal variable as Long
' NULL          ByVal Nothing or ByVal 0& or vbNullString
' SHORT         ByVal variable as Integer
' VOID          Sub Procecure not applicable
' WORD          ByVal variable as Integer
' WPARAM        ByVal variable as Long


'DataType Differences
'
'The following table lists data types used in the Win32 API and C-style functions. Many unmanaged libraries contain functions that pass these data types as parameters and return values. The third column lists the corresponding .NET Framework built-in value type or class that you use in managed code. In some cases, you can substitute a type of the same size for the type listed in the table.
'Unmanaged type in Wtypes.h
'               Unmanaged C language type
'                                  Managed class name
' handle        void*              System.IntPtr
' BYTE          unsigned char      System.Byte
' SHORT         short              System.Int16
' WORD          unsigned short     System.UInt16
' INT           int                System.Int32
' UINT          unsigned int       System.UInt32
' LONG          long               System.Int32
' BOOL          long               System.Int32
' DWORD         unsigned long      System.UInt32
' ULONG         unsigned long      System.UInt32
' CHAR          char               System.Char
' lpStr         Char*              System.String Or System.StringBuilder
' LPCSTR        Const char*        System.String or System.StringBuilder
' LPWSTR        wchar_t *          System.String Or System.StringBuilder
' LPCWSTR       Const wchar_t*     System.String or System.StringBuilder
' FLOAT         Float              System.Single
' DOUBLE        Double             System.Double

Leave a Reply

Your email address will not be published. Required fields are marked *