c++ - 在非VS项目中包含VS DLL

标签 c++ visual-studio qt dll

我在编写 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/

相关文章:

c++ - 连接 QTreeWidgetItem 时出错

qt - CMake 找不到 Qt5QuickCompiler

c++ - 我可以为 Boost.Spirit.Qi 中的内存分配给列表运算符 (%) 提示吗?

c++ - 在 hdf 中存储数据集(C++ 类的实例)

c++ - Windows 上的 SWIG-Ruby 入门

c++ - MSVC win32 中的 alignof(double)

编译器警告 - 参数列表有所不同

c++ - FLTK显示图像

c++ - 如何在c++17中定义函数组合?

python - 在另一个 Pyside/Pyqt 屏幕上调用函数