无法从 C DLL 调用该函数
Not able to call the function from C DLL
//DLL Code
#include <stdio.h>
extern "C"
{
__declspec(dllexport) void DisplayHelloFromDLL()
{
printf("Hello from DLL !n");
}
}
//Program Accessing DLL
#include<windows.h>
#include<iostream>
#include<conio.h>
typedef void (*DisplayHelloFromDLLFuncPtr)();
using namespace std;
int main()
{
HINSTANCE hGetProcIDDLL = LoadLibrary("L:\C_Learning\Library\MyLib\Debug\MyLib.dll");
if (!hGetProcIDDLL)
{
cout << "nCould Not The Library";
return EXIT_FAILURE;
}
else
{
cout << "nDLL is Loaded";
}
DisplayHelloFromDLLFuncPtr LibMainEntryPoint=(DisplayHelloFromDLLFuncPtr)GetProcAddress(hGetProcIDDLL, "DisplayHelloFromDLL");
if (!DisplayHelloFromDLL)
{
cout << "nCould not locate the function";
return EXIT_FAILURE;
}
cout << DisplayHelloFromDLL();
return EXIT_SUCCESS;
_getch();
return 0;
}
代码执行直到 cout 语句处于其他条件。
编译 DLL 中的函数时收到错误。
收到错误"显示HelloFromDLL":未声明的标识符
Ran Depends.exe它确认 DLL 地址空间中的函数可用性。
DLL 和示例程序是使用 32 位环境编译的。
6.程序的唯一目的是调用函数C DLL并打印来自DLL的Hello From消息。
有什么建议吗?
您将包含"DisplayHelloFromDLL"函数指针的变量命名为"LibMainEntryPoint":
DisplayHelloFromDLLFuncPtr LibMainEntryPoint=(DisplayHelloFromDLLFuncPtr)GetProcAddress(hGetProcIDDLL, "DisplayHelloFromDLL");
但随后您尝试使用不同的名称(DisplayHelloFromDLL(:
if (!DisplayHelloFromDLL) ...
与变量名称一致,代码应该可以工作。将其更改为:
DisplayHelloFromDLLFuncPtrDisplayHelloFromDLL=(DisplayHelloFromDLLFuncPtr(GetProcAddress(hGetProcIDDLL, ">DisplayHelloFromDLL"(;
相关文章:
- 如何用参数值调用函数(仅在运行时已知)
- 从python中调用C++函数并获取返回值
- 当使用通配符和null指针调用函数时,对输出的说明
- 从R调用C++函数并对其进行集成时出错
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 如何在qt中从另一个类调用函数
- 在 COUT 语句中使用 COUT 调用函数
- 如何从线程中的不同模块调用函数?
- C++从函数指针数组调用函数
- 当 A 在 for 循环中调用函数 B 时,如何计算函数 A 的空间复杂度?
- 如何在 C/C++ 中从外部库调用函数
- 如何使用运算符在同一行中多次调用函数
- 是否可以创建一个从不同类调用函数的线程?
- 无法为类成员调用函数
- 如何从另一个标头 c++ 调用函数
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 如何只允许在调用函数 B 后调用函数 A?
- 我可以这样调用函数吗?
- 如何在 c++ 的类中递归调用函数方法?
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?