Matt Phillips
Matt Phillips

Reputation: 9691

Include VS DLL in non-VS project

I don't have much experience with either writing DLLs or Visual Studio. Basically I want to use a DLL created in Visual Studio in a non-VS (namely, Qt) project. The .h file for the default DLL (VS2010) is:

// test-lib.h

#pragma once

using namespace System;

namespace testlib {

    public ref class Class1
    {
        //...
    };
}

I'm able to build the DLL without any problem, but I don't know how to include it in my Qt project. That is, when I try to compile it I get

..\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.

This is despite the fact that I'm compiling with VS2012's compiler and my version of Qt was built with it as well. Does anyone know how I can make this work? In my .pro file I currently have the dll added to LIBS, are there other dlls I need to add?

Upvotes: 0

Views: 189

Answers (1)

d953i
d953i

Reputation: 51

Assuming your DLL written in C with symbol exports and etc.

typedef void (*NameOfMyDLLFunction)(double* data, int size);
QLibrary* myLibrary = new QLibrary("NameOfMyLibraryFile", this);

myLibrary->load();

NameOfMyDLLFunction dllFunction = reinterpret_cast<NameOfMyDLLFunction(myLibrary->resolve("dllFunction "));

Now you can call your dllFunction(double* data, int size).

Upvotes: 1

Related Questions