我在我的c ++代码中加载了一个dll,但在运行时我得到错误:
DLL:
`extern "C" __declspec(dllexport) int Add(int a,int b)
{
return a+b;
}`
我的控制台文件:
typedef int(__stdcall *f_funci) (int , int);
int main()
{
HINSTANCE hGetProcIDDLL = LoadLibrary("ConsoleApplication1.dll");
if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
system("pause");
return EXIT_FAILURE;
}
f_funci funci = 0;
funci = (f_funci)GetProcAddress(hGetProcIDDLL, "Add");
if (!funci) {
std::cout << "could not locate the function" << std::endl;
system("pause");
return EXIT_FAILURE;
}
int t = 0;
t= (*funci)(2, 3);
std::cout << "funci() returned "<<t<< std::endl;
system("pause");
return EXIT_SUCCESS;
}
答案 0 :(得分:0)