In a VB addressof to ask you a question

Addressof followed by the function name, you can take parameters? I parentheses then directly in parentheses write parameter is wrong

Thank you

Started by Sheryl at December 31, 2016 - 6:50 AM

The AddressOf operator

A unary operator, it will transfer the address to a API process, the API process parameters in the position corresponding to a function pointer.


AddressOf procedurename

The required procedurename to specify the delivery address is a process which address. This process must be a process of a standard module module sends commands to engineering in.


When the name of a process in a parameter list, the process has been calculated, and the process of the value of the return address will be passed. The AddressOf allows the process address is passed to a dynamic link library (DLL) of a Windows in the API function return value, instead of passing the process. The Basic function of the API can then use this address to call the corresponding, this process is known as the callback. The AddressOf operator only appeared in the process of API calls.

Although you can use the AddressOf operator to transfer process between the pointer in the Basic, but not through a pointer that from inside the Basic calls a function. That is to say, for example, use Basic to prepare a class cannot use a pointer to its controller callbacks. When the pointer is a process between process using the AddressOf operator in the Basic, is the parameter type of the calling process must be defined as a As Long.

Warning if you do not fully understand the concept of the callback function, use the AddressOf operator may lead to beat all results. Section Basic must understand the callback is how to work, and accept the transfer function DLL addresses how the code works. Debugging interactive operation it is very difficult, because the program and development environment running in the same process. In some cases, the debugging of the system may be impossible.

Note that you can use the Microsoft Visual C++ (or a similar tool) compiled DLLs to create their own callback function prototype. To use the AddressOf operator to work, your prototype must use the __stdcall calling convention. The default calling convention (__cdecl) can not work with the AddressOf operator.

Because a callback procedure call is not in the user program, so it is important to ensure the callback process errors are not returned to the caller. Through the initial On Error Resume Next statement is placed in the callback process to meet this requirement.

Posted by Sharon at January 11, 2017 - 7:05 AM