![]() |
Technical ArticlesData Type Conversion Chart for VB, VBA, and WinBatch |
David A. Gray, MBA
Chief Wizard, WizardWrx
The chart below lists data types commonly found in C header files and documentation of functions exposed by the Microsoft Windows API and others. Equivalents are shown for a number of commonly used programming languages. Use them to convert argument types for use with your favorite language and gain access to the power of the Win32 API and other low level APIs.
| C/C++ | VB/VBA | WinBatch | Assembly | Size | Comments |
| BOOL | Boolean | @true/@false | LONG | 4 | This value is returned as a Long Integer with a value of -1 for True and 0 for False. See Note 1. |
| WORD | Integer | Word | Word | 2 | On current 32 bit platforms, this is a 16-bit integer. |
| INT | Integer | Word | Word | 2 | On current 32 bit platforms, this is cast as a 16-bit integer, just as it is on 16 bit platforms. |
| DWORD | Long | Long | LONG | 4 | This type is vaguely deprecated in favor of LONG. |
| LONG | Long | Long | LONG | 4 | Most 32 bit Windows functions that return integers are of this type. The corresponding 16 bit functions return a value of type INT. If you have documentation only for the 32 bit version of a Windows API function, you can usually substitute INT for any value of type LONG, and vice versa. |
| HANDLE | Long | Long | LONG | 4 | This type is cast to a LONG in 32 bit C/C++ code and to a WORD or INT in 16 bit C/C++ code, hence, the reason for it to be a type unto itself. See Note 2.. |
| HINSTANCE | Long | Long | LONG | 4 | This type is cast to a LONG in 32 bit C/C++ code and to a WORD or INT in 16 bit C/C++ code, hence, the reason for it to be a type unto itself. See Note 2.. |
| HWND | Long | Long | LONG | 4 | This type is cast to a LONG in 32 bit C/C++ code and to a WORD or INT in 16 bit C/C++ code, hence, the reason for it to be a type unto itself. See Note 2.. |
| LPSTR | Long | Long | LONG | 4 | This type is differentiated from an ordinary LONG because it is a pointer to a string. See Note 3.. |
| LPCSTR | Long | Long | LONG | 4 | This is equivalent to type LPSTR, except that a C compiler treats this as a call by value and prevents the caller's copy from being modified. See Note 3.. |
| LPTSTR | Long | Long | LONG | 4 | This is equivalent to type LPSTR, except that there are two versions of the function, one expecting an ANSI string, and the other expecting a Unicode string. See Note 3.. |
| LPCTSTR | Long | Long | LONG | 4 | This is a combination of the above two types, LPTSTR defining a string of TCHARS, which may be either ANSI or Unicode, depending on the context, which is passed by value, to prohibit the called function from changing the string. See Note 3.. |
if DllCall ( KernelFQFN , long:"GetVolumeInformationA" , lpstr:RootPathName , lpnull , long:0 , lpnull , lpnull , long:dwSysFlags , lpbinary:hFileSysNameBuf , long:BUFSIZE )
GetVolFileSystem_P6C in my WILPower framework for WinBatch scripts.
Declare Function GetFocus Lib "user32" () As Long
Dim hWnd as Long
hWnd = GetFocus ( )
hWnd = DllHWnd
OR
hWnd = DllCall ( ( StrCat ( DirWindows ( 1 ) , 'USER32.DLL' ) , long:'GetFocus' )
Dim strAPIBuff As String * 100
hBuff = BinaryAlloc ( NBytes )
NBytes is the required size of the buffer. For ANSI file names and most other purposes, 260 is plenty. Pass script variable hBuff to the function using the lpbinary type prefix. Use code similar to the following to retrieve the data.
Dummy = BinaryEODSet ( hBuff , lResult )
MyString = BinaryPeekStr ( hBuff , lResult )
hBuff = BinaryFree ( hBuff )
lResult is the return value from the function, usually an INT or LONG, which is the number of bytes or characters of valid data left in hbuff by the function.
CallResult = DllCall ( KernelFQFN , long:"GetVolumeInformationA" , lpstr:RootPathName , lpnull , long:0 , lpnull , lpnull , long:dwSysFlags , lpbinary:hFileSysNameBuf , long:BUFSIZE )
GetVolFileSystem_P6C in my WILPower framework for WinBatch scripts.
[in] means that data flows from the caller to the function.[out] means that data flows from the function to the caller.[in/out] means that data flows from the caller to the function and back. Treat this the same as [out].Internal representation of single, double precision, and floating point numbers is beyond the scope of this article. Perhaps I shall write one another day. My present programming practice never requires use of such numbers in such low level code.
GUI Programming Lectures is part of a university course on Windows programming, taught at Niagara College in Welland, Ontario, Canada, that discusses these matters in much greater detail. Though written from the perspective of a C programmer, you may find the material enlightening. In any case, the included tables cover every data type that you are likely to encounter in Windows programming.