我在编写 DLL 或 Visual Studio 方面经验不多。基本上我想在非 VS(即 Qt)项目中使用在 Visual Studio 中创建的 DLL。默认 DLL (VS2010) 的 .h
文件是:
// test-lib.h
#pragma once
using namespace System;
namespace testlib {
public ref class Class1
{
//...
};
}
我可以毫无问题地构建 DLL,但我不知道如何将它包含在我的 Qt 项目中。也就是说,当我尝试编译它时,我得到了
..\test-lib.h:6: error: C2871: 'System' : a namespace with this name does not exist ..\test-lib.h:10: error: C2059: syntax error : 'public' ..\test-lib.h:11: error: C2143: syntax error : missing ';' before '{' etc.
尽管我正在使用 VS2012 的编译器进行编译,而且我的 Qt 版本也是使用它构建的。有谁知道我怎样才能使这项工作?在我的 .pro
文件中,我目前已将 dll 添加到 LIBS
,是否还有其他我需要添加的 dll?
最佳答案
假设您的 DLL 是用 C 语言编写的,带有符号导出等。
typedef void (*NameOfMyDLLFunction)(double* data, int size);
QLibrary* myLibrary = new QLibrary("NameOfMyLibraryFile", this);
myLibrary->load();
NameOfMyDLLFunction dllFunction = reinterpret_cast<NameOfMyDLLFunction(myLibrary->resolve("dllFunction "));
现在您可以调用您的dllFunction(double* data, int size)
。
关于c++ - 在非VS项目中包含VS DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14017159/