2 wlong724 WLONG724 于 2013.12.19 23:07 提问

C++累实现的DLL动态使用时GetProcAdress返回0

大家好,我使用C++类做成DLL,静态调用都成功了,但是动态调用时GetProcAdress一直返回0.DLL已经加载成功了。
DLL头文件:
namespace MathFuns
{
class MyMathFun
{
public:

    //return a + b
      _declspec(dllexport) double Add(double a, double b);

    //return a - b
     _declspec(dllexport) double Subtract(double a, double b);

    //return a * b
     _declspec(dllexport) double Multiply(double a, double b);

    //return a / b
     _declspec(dllexport) double Divide(double a, double b);
};

}

Dll调用CPP
int main()
{
double a = 10, b = 0;

typedef double (*pAdd)(double a, double b);

HINSTANCE  hDll = NULL;

hDll = LoadLibrary(L"MathFuncsDll.dll"); 

if(NULL == hDll)
{
    cout << "hDll is null!" << endl;
}

pAdd Add = (pAdd)GetProcAddress(hDll, "Add");
if(NULL == Add)
{
    // handle the error
    FreeLibrary(hDll);
    cout << "GetProcAddress Err! " <<  GetLastError() <<endl;
    Sleep(INFINITE);
}

cout << " a + b = "<< Add(a, b) << endl;

Sleep(INFINITE);

return 0;

}

执行后会出现:GetProcAddress Err! 0
麻烦大家帮我看下,谢谢了!

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.19 11:45
Csdn user default icon
上传中...
上传图片
插入图片