15,471
社区成员
发帖
与我相关
我的任务
分享
class A{
public:
void methodA()
{
HMODULE h= LoadLibrary("test.dll");
//接下来这里应该怎么写才能将methodB这个方法传给test.dll程序中的test方法呢?
//需要再声明一个类函数指针做为成员变量吗?
}
void methodB(int x)
{
}
}
....
void test(//这里应该怎么接收主程序的那个函数指什啊?这里参数怎么写呢?)
{
}
.....
//DLL.h文件
#ifdef TEST_DLL_API
#else
#define TEST_DLL_API extern "C" _declspec(dllexport)
#endif
#include <string>
using std::string;
typedef void (*webCallBackFun)(string ,int ,string);
TEST_DLL_API void md5(char* id,char* fname,webCallBackFun webCallBack);
DLL.cpp文件
#define TEST_DLL_API extern "C" _declspec(dllexport)
#include "stdafx.h"
#include "vdba.h"
#include "stdio.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
void md5(char* id,char* fname,webCallBackFun wcb){
::MessageBox(NULL,"Md5方法开始调用begin","md5提示:",0);
/* HANDLE handle = CreateThread(NULL, 0, ThreadFun, NULL, 0, NULL);
WaitForSingleObject(handle, 0);
webCallBack = wcb;*/
wcb("f:aaaa.txt",10,"this is ");
::MessageBox(NULL,"Md5方法开始调用end","md5提示:",0);
}
//主程序文件
// testDll.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <string>
using std::string;
void WebCallBack(string s,int id,string result){
MessageBox(NULL,"WebCallBack","提示",MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HMODULE h = LoadLibrary("c:\\vdna.dll");
if( h==0){
MessageBox(NULL,"加载失败1","提示",MB_OK);
return S_OK;
}
typedef void (*webCallBackFun)(string ,int ,string);
typedef void (*Md5Fun)(char *id, char* filename,webCallBackFun);
Md5Fun md5 = (Md5Fun)GetProcAddress(h,"md5");
MessageBox(NULL,"11111111111","马上调用md5",MB_OK);
md5("10","c:\test.txt",WebCallBack);
MessageBox(NULL,"2222222222","",MB_OK);
return 0;
}