Home   .......

Using Windows API in VB Tutorial

API parameter types

Products  
eXamples  
Files  
e-Mail Us  
 

 

When you already have a SDK Help, you will surely notice that functions return values and parameters have some strange types like VOID, LPCSTR or DWORD. If you are familiar with C, then you know what they mean. For the rest, here is a table taken from VB Books Online (topic is Converting C Declarations to Visual Basic):

C language data type
In Visual Basic declare as
Call with
ATOM ByVal variable As Integer An expression that evaluates to an Integer
BOOL ByVal variable As Long An expression that evaluates to a Long
BYTE ByVal variable As Byte An expression that evaluates to a Byte
CHAR ByVal variable As Byte An expression that evaluates to a Byte
COLORREF ByVal variable As Long An expression that evaluates to a Long
DWORD ByVal variable As Long An expression that evaluates to a Long
HWND, HDC, HMENU, etc. ByVal variable As Long An expression that evaluates to a Long
INT, UINT ByVal variable As Long An expression that evaluates to a Long
LONG ByVal variable As Long An expression that evaluates to a Long
LPARAM ByVal variable As Long An expression that evaluates to a Long
LPDWORD variable As Long An expression that evaluates to a Long
LPINT, LPUINT variable As Long An expression that evaluates to a Long
LPRECT variable As type Any variable of that user-defined type
LPSTR, LPCSTR ByVal variable As String An expression that evaluates to a String
LPVOID variable As Any Any variable (use ByVal when passing a string)
LPWORD variable As Integer An expression that evaluates to an Integer
LRESULT ByVal variable As Long An expression that evaluates to a Long
NULL As Any or ByVal variable As Long ByVal Nothing or ByVal 0& or vbNullString
SHORT ByVal variable As Integer An expression that evaluates to an Integer
VOID Sub procedure Not applicable
WORD ByVal variable As Integer An expression that evaluates to an Integer
WPARAM ByVal variable As Long An expression that evaluates to a Long

Notes:

You should notice that the BOOL type (boolean) evaluates to Long and not Boolean. So, 0 refers to False and any other value to True.

HWND, HDC, HMENU, etc. - etc. means there are also other types like these. All of them begin with H and stand for handles for different type of objects. For example HBITMAP is a bitmap handle, HBRUSH is a brush handle and so on. They all evaluate to Long and should be passes ByVal.

Notice also that LPVOID is declared as variable As Any. There is a separate topic dedicate to Any.

Some types begin with LP. It is an abbreviation of Long Pointer to. So LPWORD is actually a memory location where the data is stored. No, you won't have to call a function to get this address. When you pass your argument ByRef (the default) you actually pass its address. The thing to remember here is that, if you parameter type begins with LP - you should pass it ByRef. By the way LPARAM is like Lparam and not LParam. It is not a pointer. You must pass the actual value here, so it is passed ByVal.

There is also some strange type NULL. You know from VB so I won't discuss it here. Just choose a way you will pass it when needed. In most of the cases I see passing it as ByVal 0& or as vbNullString.

And lastly, VOID is used for functions return value to specify that there is no such value. API does not have Subs so this is the way it implements them. Just remember - if the function is declared as VOID - you must declare it as Sub in your VB code.

 
Copyright (c) 1998, Billy&George Software and Peter Dimitrov
Revised March 2000