Make Qt dll and use it in Visual Basic

My task is to make a Qt dll, which will be used in Visual Basic.
I found a couple articles, which says about making C++ dlls for VB, but, looks like, there is something special for Qt, so no matter how much did i try to do it, it just doesn’t work.

First I found an article about making C/C++ dlls for VB. At the end of the article it says:

For DLLs to be called by programs written in Visual Basic, the alias
technique shown in this topic is needed in the .def file.

It was pretty hard to understand, how to even add a .def file to a Qt project.
I’m not sure, but it looks like DEF_FILE = def.def is worked.
In def.def I wrote

LIBRARY TestLibrary
EXPORTS
    SUM = _sum@#

for function

int __stdcall func sum(int a, int b) { return a + b; }

‘#’ – because I don’t know

number of bytes in the argument list (the required stack space)

For this we need to use /MAP, which I didn’t found how to use in Qt

Then I tried this like so:

int sum(int a, int b) { return a + b; }

LIBRARY TestLibrary
EXPORTS
    sum     @1

and it doesn’t work too.

And [this][3] is a dead duck too.

[This][4] question has no ansver for me.

All of my code:

TestLibrary.pro

QT       -= gui

TARGET = TestLibrary
TEMPLATE = lib

VERSION = 1.0.0

DEFINES += TESTLIBRARY_LIBRARY

SOURCES += testlibrary.cpp

HEADERS += testlibrary.h
    testlibrary_global.h

DEF_FILE = def.def

unix {
    target.path = /usr/lib
    INSTALLS += target
}

DISTFILES += 
    def.def

testlibrary.h

#ifndef TESTLIBRARY_H
#define TESTLIBRARY_H

#include "testlibrary_global.h"
#include <stddef.h>

class TESTLIBRARYSHARED_EXPORT TestLibrary
{
public:
    int sum(int a, int b) { return a + b; }
};

#endif // TESTLIBRARY_H

testlibrary_global.h

#ifndef TESTLIBRARY_GLOBAL_H
#define TESTLIBRARY_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(TESTLIBRARY_LIBRARY)
#   define TESTLIBRARYSHARED_EXPORT Q_DECL_EXPORT
#else
#   define TESTLIBRARYSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // TESTLIBRARY_GLOBAL_H

testlibrary.cpp

#include "testlibrary.h"

def.def

LIBRARY TestLibrary
EXPORTS
    sum     @1

PS sorry for my awful english =P

3: https:// msdn.microsoft .com/en-gb/library/a90k134d.aspx

4: https:// stackoverflow .com/questions/19730906/using-my-c-qt-library-dll-in-visual-basic


Source: dll

Leave a Reply