功能在DLL中
Functions in a DLL
我具有一些功能的DLL。标题示例:
__declspec(dllexport) bool Test()
;而且我还有另一个简单的应用程序可以使用该功能:
typedef bool(CALLBACK* LPFNDLLFUNC1)();
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
bool uReturnVal;
hDLL = LoadLibrary(L"NAME.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"Test");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
cout << "error";
}
else
{
// call the function
uReturnVal = lpfnDllFunc1();
}
}
但不工作。找不到该功能。
我的心理感官告诉我,没有找到该功能,因为您忘了将其声明为extern "C"
。
由于c 中的名称杂交,如果函数具有C 链接,则将被放入DLL导出表中的实际函数名称比Test
更长,更Gibberish-Y字符串。如果您使用C链接声明它,则将其导出预期名称,因此可以更轻松地导入。
例如:
// Header file
#ifdef __cplusplus
// Declare all following functions with C linkage
extern "C"
{
#endif
__declspec(dllexport) bool Test();
#ifdef __cplusplus
}
// End C linkage
#endif
// DLL source file
extern "C"
{
__declspec(dllexport) bool Test()
{
// Function body
...
}
} // End C linkage
相关文章:
- MFC/DLL中缺少ATL :: CSTRINGT功能,该功能与Clang/vs-2019构建
- 加载所有DLL功能
- 在C 功能执行后,使用GCHANDLE CRALSES将大型结构从C#Unity脚本传递到C DLL
- 来自Pascal DLL/SO中的C 加载和调用功能
- 我应该如何分享该过程和多个DLL之间的功能列表
- 通过功能指针通过DLL进行回调功能,运行时检查失败#0错误
- 从DLL到EXE C 的呼叫功能
- 使用C /CLI包装器DLL时缺少功能
- 如何从Java中的C DLL加载和使用结构和功能
- 我可以用具有相同功能名称的多个DLL加载元素吗?
- C 通过引用DLL中的功能传递std ::字符串
- 调用包含C#功能指针的DLL函数
- 在DLL中导出功能.C和C
- 从X86 DLL获取导出功能
- 如何从Delphi编译的DLL中调用C 中的功能
- 功能在DLL中
- 错误:在C#中调用C DLL功能
- 如何将多个静态链接库合并到一个dll中,给定每个静态库定义导出的功能(vc++2008)
- c静态库在cpp dll中的功能
- 是否有用于修改AutoHotkey_L中DLL调用功能的标准协议