A lot of people have requested an API guide to convert their WinAPI declarations
in C or VB to use with Rapid-Q, so here is a basic summary with some brief explanations.
Special thanks to Mayuresh S. Kadu for this WIN32 API in VB guide.
C data type | Pascal | VB | Rapid-Q |
ATOM | SHORT | byval as INTEGER | SHORT |
BOOL | BOOLEAN | byval as LONG | LONG |
BYTE | BYTE | byval as BYTE | BYTE |
CHAR | CHAR | byval as BYTE | BYTE |
CHAR[20] | STRING[20] | as STRING | N/A in API Declarations |
COLORREF | LONGINT | byval as LONG | LONG |
DWORD | DWORD | byval as LONG | DWORD |
Windows handles ie. HDC | Windows Handles | byval as LONG | LONG |
INT, UINT | INTEGER, DWORD | byval as LONG | INTEGER, DWORD |
LONG | LONGINT | byval as LONG | LONG |
LPARAM | LONGINT | byval as LONG | LONG |
LPDWORD | ^DWORD | as LONG | BYREF as DWORD |
LPINT, LPUINT | ^INTEGER | as LONG | BYREF as LONG |
LPRECT | ^TRECT | as ANY | QRECT |
LPSTR, LPCSTR | PCHAR | byval as STRING | BYREF as STRING |
LPVOID | LONGINT | as ANY | LONG |
LPWORD | ^WORD | as INTEGER | BYREF as WORD |
LRESULT | LONGINT | byval as LONG | LONG |
NULL | NIL | byval as LONG | LONG |
SHORT | SHORT | byval as INTEGER | SHORT |
WORD | WORD | byval as INTEGER | WORD |
WPARAM | LONGINT | byval as LONG | LONG |
For those data types in red, they are pointers to the variable.
In Rapid-Q, this requires using VARPTR in passing the address of the variable, and not the
value of the variable. Here's some sample conversions:
In VB:
DECLARE SUB Test LIB "USER32" ALIAS "What" _
(byval L AS LONG, byval S AS STRING)
Test (1230, "Hello world!")
In Rapid-Q:
DECLARE SUB Test LIB "USER32" ALIAS "What" _
(byval L AS LONG, byval S AS STRING)
Test (1230, "Hello world!")
Nothing different there, note that Rapid-Q doesn't use BYVAL, so you can ignore
putting them there. In the above example, the string is passed by reference, ie.
the address of the string is passed, not the string itself.
Here's an example which passes the whole string (not the address, so it involves
OLE to allocate space for the string), this works fine in VB but not in Rapid-Q:
In VB:
DECLARE SUB Test LIB "USER32" ALIAS "What" _
(byval L AS LONG, S AS STRING)
Test (1230, "Hello world!")
In Rapid-Q:
Not possible, since it doesn't use OLE to allocate the string.
How about NULL strings? Here's another situation (please note that I don't use
VB much so it may be possible to declare S as STRING and pass it a vbNullString,
I'm not really sure so I'll play it safe):
In VB:
DECLARE SUB Test LIB "USER32" ALIAS "What" _
(byval L AS LONG, byval S AS LONG)
Test (1230, 0&)
In Rapid-Q:
DECLARE SUB Test LIB "USER32" ALIAS "What" _
(byval L AS LONG, byval S AS LONG)
Test (1230, 0&)
So what if we want to pass a string instead of a NULL string, then you'd need to
use VARPTR:
In VB or Rapid-Q:
DIM S AS STRING
S = "Hello world!"
Test (1230, VARPTR(S))
A NULL string basically means an address of 0.
VARPTR just returns the address of a variable.
How about other pointers, like LPWORD? A WORD is just an unsigned 16-bit number,
VB only supports signed 16-bit numbers called INTEGERs, but the general idea is
to remove the byval keyword when passing variables by reference:
In VB (doesn't support WORD, so use next best):
DECLARE SUB Test LIB "USER32" ALIAS "Another" _
(L AS INTEGER)
DIM L AS INTEGER
Test (L)
In Rapid-Q:
DECLARE SUB Test LIB "USER32" ALIAS "Another" _
(BYREF L AS WORD)
DIM L AS WORD
Test (L)
In Rapid-Q, use BYREF when passing variables by reference, in VB you don't need to
use BYREF, as the above example demonstrates.