GetProcAddress总是返回NULL
---math.h文件
#include <string>
extern "C" __declspec(dllexport) int pascal Test(int i,int j);
//extern "C" class CMath
//{
//public:
//CMath(void);
// __declspec(dllexport) int pascal Add(int i,int j);
//~CMath(void);
//};
---math.cpp文件
#include "StdAfx.h"
#include "Math.h"
int pascal Test(int i,int j)
{
return i+j;
}
VS2010,编译生成了firt.dll文件
-----------------------client----------------------
-------------test.cpp--------------
#include<iostream>
#include<windows.h>
typedef int ( _stdcall *FUN)(int,int);
int main(void)
{
HINSTANCE hinst=::LoadLibraryA("first.dll");
if(NULL != hinst)
{
std::cout<<"DLL is Load"<<std::endl;
FUN f=(FUN)GetProcAddress(hinst,"1");
if(f==NULL)
{
std::cout<<"Error"<<std::endl;
}
else
{
int k=f(2,3);
std::cout<<k<<std::endl;
}
}
else
{
std::cout<<"Dll isn't Load"<<std::endl;
}
std::cin.get();
}
loadlibrary能成功,但是GetProcAddress总是返回NULL。请问为什么?
[解决办法]
GetProcAddress要填导出函数的名字
[解决办法]
说明你的dll还是C++规范的
[解决办法]
把pascal换成__stdcall试试
[解决办法]
不要用__declspec(dllexport)
用def文件或者link的/export参数
[解决办法]
_Test@8 就是vc的c风格的修饰名
你不加extern "C"更乱