C++ Loading a DLL
C++ Loading a DLL
我即将开发应使用DLL分发的API。因为我无法直接测试我的代码,所以我必须将DLL加载到测试项目中并在此处运行。
我正在使用Visual Studios2015。在那里我进行了一个测试项目,在此中,我为DLL做了我的项目:
solution-tree" testproject"
-
dllproject
-
testProject
我导出一个虚拟功能,以测试是否能够加载DLL:
#ifndef EXPORT
#define EXPORT __declspec(dllexport)
#endif
extern "C" {
EXPORT int dummy() {
return 5;
}
}
然后,在我的testproject中,我尝试加载DLL,提取功能并运行它:
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (__stdcall *dll_func)();
int main() {
HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("H:\path\to\project\Debug\DLLProject\DLLProject.dll"));
if (hGetProcIDDLL == NULL) {
cout << "DLL could not be loaded. " << GetLastError() << endl;
return;
}
dll_func f = (dll_func)GetProcAddress(hGetProcIDDLL, "create");
if (f == NULL) {
cout << "Factory function could not be resolved. " << GetLastError() << endl;
return;
}
cout << "Factory function returns: " << f() << endl;
}
我从这个问题中复制了几乎所有内容。不幸的是,当我运行testproject时,我的控制台打印出来:" DLL无法加载。4250"
在这一点上,我真的不知道该怎么办,因为此处描述的错误基本上什么也没说。有了一些研究,我无法得到任何答案...希望您可以帮助我:D
这可能是由链接器设置引起的。确保您在链接器设置中指定"/appContainer:no"。
相关文章:
- 挂起和取消挂起一个文件DLL
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 导入库可以跨dll版本工作吗
- 从C++dll访问C#中的一行主要参数
- 链接到自行创建的dll失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- C++:将外部库链接到dll库
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 不同的Visual Studio版本中缺少.dll
- 从DLL中删除类的实例
- 如何包装第三方DLL在R中使用
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
- Python ctypes:不会按预期加载 dll
- C++ Loading a DLL