Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

 
  .......
Using Windows API in VB Tutorial
Handling Parameters
 
 
 
 
  Sometimes the functions do not return the information you need the way you want it. Typical example is combining two integer(2-byte) values specifying the mouse position into one 4-byte value. Another case is telling you that if bit 29 is on it means something. Also, you may receive a Long value that is the address of a structure.

Combining or separating values does not need any description. APIMacro.bas contains all functions you need to have.

To check if bit N of Value is on use the following:

If Value and (2^N) then ...

To set a bit on:

Value = Value Or 2^N

To set a bit off:

Value = Value And Not 2^N

If you set and get the state of a bit you know beforehand, its much faster to replace 2^10 with 1024. This way VB won't have to calculate it itself (VB "hates" ^).

If you receive a pointer to a type, then you must do a bit more. To get the info, you use CopyMem function. Here is the declaration:

Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" 
(pDest As Any, pSource As Any, ByVal ByteLen As Long)

If you receive a pointer to RECT type in the Long variable Addr, use the following:

Dim Info As Rect
Call CopyMem(Info, ByVal Addr, Len(Info))

Note the ByVal keyword. Now, if you need to put the information back, use:

Call CopyMem(ByVal Addr, Info, Len(Info))