Home > Software engineering >  About VB addressof ask you a question
About VB addressof ask you a question

Time:10-31

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

Thank you for the

CodePudding user response:

AddressOf operator


A unary operator, it will be followed in the process of below address is passed to an API process, the API process in the corresponding position parameter table needs a function pointer,

Syntax

AddressOf procedurename

Necessary procedurename specified for delivery address which is a process, this process must be calling command engineering of a standard module module in a process,

Description

When the name of a process in a parameter list, usually the process has been calculated, and the process will also be passed, the return value address AddressOf address is passed to allow the process dynamic link library (DLL) is one of the Windows API function, rather than pass the return value of the process, the API function and then you can use this address to invoke the corresponding Basic process, this process is that we know the callback, the AddressOf operator only appeared in the process of API calls,

Although you can use the AddressOf operator in the Basic process passed between a pointer, but not through such a pointer from the Basic internal calls a function, that is to say, for example, a use of Basic writing class cannot use such a pointer back and forth its own controller, when using the AddressOf operator in the Basic process between passing a pointer, the called process parameter types must be defined As Long,

Warning if you can't fully understand the concept of function callback, use the AddressOf operator may result in unexpected results, must understand the Basic part of the callback is how to work, and to accept the transfer function of address of the DLL code works, debugging such interactions is very difficult, because the program and development environment in the process of the same operation, in some cases, system debugging is probably impossible,

Note that you can use the Microsoft Visual c + + (or similar tool) compiled DLLs to create your own callback function prototype, to use the AddressOf operator to work, your prototype must use __stdcall calling convention, the default calling convention (__cdecl) cannot work with the AddressOf operator,

Because a callback the caller is not in your own program, so it is important to ensure that in the process of correction Error will not be returned to the caller, can be put On the Error Resume Next statement is placed in the process of the callback starting place to meet this requirement,
  • Related