永发信息网

如何在PHP中调用自己编写的DLL库中的函数接口

答案:2  悬赏:70  手机版
解决时间 2021-02-25 11:08
  • 提问者网友:蓝琪梦莎
  • 2021-02-24 14:07
如何在PHP中调用自己编写的DLL库中的函数接口
最佳答案
  • 五星知识达人网友:渡鹤影
  • 2021-02-24 15:24
在 DLL工程中的 cpp中函数定义如下:

extern "C" _declspec (dllexport )
int fun(int a, char b)
{
return a + b;
}
第一种方法 隐式调用:

调用的 DLL的主工程的 文件中代码如下:

// 先把 lib 链接进来
#pragma comment (lib , "..//Debug//FuncDll.lib" )

// 外部声明的 add 函数
extern "C" _declspec (dllimport )
int fun(int a, char b);

int TestDll()
{
// 直接调用 fun函数
printf("%d/n" , fun(5, 2));

return 0;
}
第二种方法 显式调用:
调用的 DLL的主工程的 文件中代码如下:

int TestDLL()
{
HMODULE hModule = NULL;
typedef int (*Func)(int a, int b);

// 动态加载 DLL 文件
hModule = LoadLibrary(_TEXT("..//Debug//FuncDll.dll" ));

// 获取 fun函数地址
Func fAdd = (Func)GetProcAddress(hModule, "fun" );

// 使用函数指针
printf("%d/n" , fAdd(3, 1));

// 释放指针
FreeLibrary(hModule);

return 0;
}
全部回答
  • 1楼网友:深街酒徒
  • 2021-02-24 15:57
我。。知。。道 加。。我。。私。。聊
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯