Home

About Us

Books

Free Stuff

Oh, So That's How It Works!

Fellow Magicians

Useful Links



WizardWrx Logo

Technical Articles

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

Notes

  1. Functions that return true or false can be called inline from the condition clause of an if statement as shown below.

    if DllCall ( KernelFQFN , long:"GetVolumeInformationA" , lpstr:RootPathName , lpnull , long:0 , lpnull , lpnull , long:dwSysFlags , lpbinary:hFileSysNameBuf , long:BUFSIZE )

    Note the unavoidable line wrap in this working example, taken from function GetVolFileSystem_P6C in my WILPower framework for WinBatch scripts.
  2. Many Win32 API functions require a window handle, usually to the main window of the program making the call.
  3. How you specify arguments of type LPSTR and LPTSTR depends upon which way data flows between the caller and the called function.
  4. Arguments of type LPCSTR and LPCTSTR must be passed by value. Pass the name of the WIL variable that contains the string, like this.

    CallResult = DllCall ( KernelFQFN , long:"GetVolumeInformationA" , lpstr:RootPathName , lpnull , long:0 , lpnull , lpnull , long:dwSysFlags , lpbinary:hFileSysNameBuf , long:BUFSIZE )

    Note the unavoidable line wrap in this working example, taken from function GetVolFileSystem_P6C in my WILPower framework for WinBatch scripts.
  5. You can usually tell at a glance which way the data flows by the way the arguments are marked.

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.




P6C Contact Info

Copyright and Legal Notice