How to implement the VB in the DLL library callback?
Namely: VB call DLL library, VC do want to callback the VB function in the DLL, the need to do?
Thank you very much!
CodePudding user response:
//a.c pp: Defines the entry point for the DLL application.
//
# include "stdafx. H"
Extern "C" void _declspec (dllexport) CallVBFunction (void);
//void CallFunc (void)
__declspec (naked) void CallVBFunction (void)
{
The __asm
{
Pop eax.//return address the stack
Pop ecx;//function pointer out stack
Push eax.//return address into the stack
JMP ecx.//function call
}
}
CodePudding user response:
AddressOf is VB function pointer, can through the transfer function pointer to the function of VC,Statement in VB VC function, using Any type of statement function pointer variable,
In VC need to first define the function model, then using function model in callback parameters define variables, such as:
/* callback function model definition */
LPVBFUN typedef void (*) (void);
/* API function definitions for VB lpVBFunction callback function */
Void _stdcall YourAPI (LPVBFUN lpVBFunction)
{
LpVBFunction ();
}
Private Declare Sub YourAPI Lib "YourAPI. DLL (lpVBFunction As Any)
Private Sub Form_Load ()
YourAPI AddressOf VBFunction
End Sub
Private Sub VBFunction ()
MsgBox "this is a VB callback function", "
End Sub