請教各位:
如何在dll庫中實作VB的回呼?
也就是:VB呼叫VC做的dll庫,想在dll中回呼VB函式,這個需要怎么做?
謝謝!
uj5u.com熱心網友回復:
// a.cpp : 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)
{
__asm
{
pop eax; //回傳地址出堆疊
pop ecx; //函式指標出堆疊
push eax; //回傳地址入堆疊
jmp ecx; //呼叫函式
}
}
uj5u.com熱心網友回復:
AddressOf 是取得VB函式的指標,可以通過這個傳遞函式指標給VC函式。在VB中宣告VC函式時,用 Any 型別宣告函式指標變數。
在VC中需要先定義函式模型,然后在回呼引數中用函式模型定義變數,如:
/* 回呼函式模型定義 */
typedef void (*LPVBFUN)(void);
/* API函式定義 lpVBFunction 為VB回呼函式*/
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 "這是VB回呼函式"
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/28660.html
標籤:VB基礎類
上一篇:vb6.0圖片保存
