How to Pass a Point Structure to the Windows API by ValueLast reviewed: October 30, 1995Article ID: Q138518 |
The information in this article applies to:
SUMMARYThe WindowFromPoint and ChildWindowFromPoint API functions require that a Point structure be passed by value. Visual Basic is not capable of passing a structure by value, only by reference. However, it is possible to pass the elements of the user-defined type in the correct order so that these API functions can be used. This article explains and demonstrates how to pass the Point structure by value to the API in the 16-bit and 32-bit editions of Visual Basic.
MORE INFORMATIONThe Windows 16-bit API is unusal because it allows you to pass the Point structure to the WindowFromPoint functions by value. Typically, user- defined types are passed to functions by reference because passing them by value can use up a lot of stack space and be much slower than passing the address of the structure. An exception was made for the Point structure in certain functions (such as ChildWindowFromPoint and WindowFromPoint) because in 16-bit programming the size of the structure was only 32 bits long, which is the same length as a far address anyway. However, on a 32-bit operating system, this structure becomes 64 bits. To preserve compatibility, Microsoft decided that the Point structure should still be passed by value for these two API functions in the 32-bit user dynamic link library (DLL). Visual Basic is not capable of passing structures by value, but the value of the elements of the structure can be placed on the stack in the correct order. Therefore, when passing the elements of the Point structure in 32-bit programming, two long values should be passed. When passing the elements in 16-bit programming, two integers should be passed to the function. Another important consideration is that 32-bit Visual Basic uses the C convention (stdcall) of passing parameters. This convention specifies that arguments are placed on the stack from right to left. 16-Bit Visual Basic maintains the Pascal convention of passing parameters from left to right. (API functions are declared using the Pascal calling convention.) As a result, the elements of the structure must be listed in reverse order (that is, element y followed by x) when calling the WindowFromPoint function using 32-Bit Visual Basic. When using 16-bit Visual Basic, element x is passed to the API function before element y.
Step-by-Step Example of How to Call the WindowFromPoint APIThe code in the following example uses conditional compilation so that the code can be placed in either the 16-bit or 32-bit version of Visual Basic.
|
Additional reference words: 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |