我尝试动态加载 C++ dll,首先我使用“LoadLibrary”函数加载了 dll,它正在正确获取它的句柄。之后我尝试使用“GetProcAddress”获取 DLL 文件函数的函数指针,它返回 NULL。请找到我的 DLL 代码和测试应用程序代码,让我知道代码哪里出了问题。
dummy2.h
namespace newer
{
class dllclass
{
public:
static __declspec(dllexport) int run(int a,int b);
};
}
dummy2.cpp
#include <iostream>
using namespace std;
#include "dummy2.h"
namespace newer
{
int dllclass::run(int a,int b)
{
return a+b;
}
}
dummy1.cpp
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (*Addition)(int,int);
int _tmain(int argc, _TCHAR* argv[])
{
Addition add;
HINSTANCE hDLL;
hDLL = LoadLibrary(TEXT("Dummy2.dll"));
add = (Addition)GetProcAddress(hDLL, "run");
getchar();
return 0;
}
请参考上面的代码并指导我。