Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create a shared Dll to be used in a vb.net or c# application

Create a shared Dll to be used in a vb.net or c# application

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheCrowKaka
    wrote on 4 Feb 2017, 16:38 last edited by
    #1

    I am trying to find out how to use ActiveQt to create a in-process dll which can be used in a vb.net or c# or vb6 application. Somehow I am totally confused with the documentation that i have read and hence thought of asking the question on the forum to the experts.

    My environment is qt5.7.1, Visual Studio 2015 Community on Windows 7.

    The shared testing library created, source code of files:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-02-04T19:10:10
    #
    #-------------------------------------------------
    
    QT       -= gui
    
    TARGET = testlibrary
    TEMPLATE = lib
    
    DEFINES += TESTLIBRARY_LIBRARY
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += testlibrary.cpp
    
    HEADERS += testlibrary.h\
            testlibrary_global.h
    
    unix {
        target.path = /usr/lib
        INSTALLS += target
    }
    
    

    the source code for testlibrary.h

    #ifndef TESTLIBRARY_H
    #define TESTLIBRARY_H
    
    #include "testlibrary_global.h"
    
    class TESTLIBRARYSHARED_EXPORT Testlibrary
    {
    
    public:
        Testlibrary();
        qreal getSum(qreal val1,qreal val2);
    
    private:
        qreal myres;
    };
    
    #endif // TESTLIBRARY_H
    
    

    The source code for testlibrary.cpp

    #include "testlibrary.h"
    
    
    Testlibrary::Testlibrary()
    {
    }
    
    qreal Testlibrary::getSum(qreal val1, qreal val2)
    {
        return val1 + val2;
    }
    

    And another file created by the creator.. 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
    

    Now I want to have this same testlibrary compiled as a DLL which can be included as a Reference in the VB.net or vb6 application and so that I can access the functions and events from a VB.net or C# or vb6 application.

    Can someone let me know the right way to do this?

    A Qt Enthusiastic...

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 4 Feb 2017, 17:59 last edited by
      #2

      Hi, you can look at some examples in Qt 5.7.1 that show how to create ActiveQt dlls, if you look for the example with the keywords *activeqt" "hierarchy" that example creates an in-process dll which you can use in vb.net.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TheCrowKaka
        wrote on 4 Feb 2017, 18:10 last edited by
        #3

        Thanks for this tip.
        I compiled the hierarchy application as a release dll.
        But when i try to include the dll as a Reference to the VB.NET project, it gives an error
        "A reference to .... dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

        Am I doing the right thing for including the DLL in VB.net or what is the right way?

        A Qt Enthusiastic...

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hskoglund
          wrote on 4 Feb 2017, 19:48 last edited by hskoglund 2 Apr 2017, 22:25
          #4

          Hi, I just tried, this way:

          1. Compile to release (You did this already)

          2. Go to the directory where the hierarchyax.dll is, in my case it is:
            cd C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
            elease\release>

          3. Use windeployqt to copy all the needed Qt dlls into that directory:
            C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
            elease\release>\qt\5.8\msvc2015\bin\windeployqt hierarchyax.dll

          4. Register the .dll as a COM dll in Windows:
            C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
            elease\release>regsvr32 hierarchyax.dll

          5. Start Visual Studio, create a new VB.net project, add the .dll as a COM reference:
            alt text

          6. Try some simple code, like this:
            alt text

          7. You should see Qt's window in the upper left corner:
            alt text

          Good luck!
          EDIT: For some reason my 3 pictures are not visible any more in Firefox, use Chrome or Safari...

          1 Reply Last reply
          2
          • T Offline
            T Offline
            TheCrowKaka
            wrote on 5 Feb 2017, 14:06 last edited by
            #5

            Hello hskoglund

            I got stuck up at the step 4 of registering the .dll as a COM dll in Windows.

            I get the typical error for which you have written the blog. "Could not find the platform plugin "windows" in "".

            I tried adding the qt.conf file, verified that all the files are copied in the directory, again copied the qwindows.dll in the location, but nothing seems to work.

            This is the directory listing with the files.
            02/05/2017 07:08 PM <DIR> .
            02/05/2017 07:08 PM <DIR> ..
            03/11/2014 04:24 PM 4,173,928 D3Dcompiler_47.dll
            02/04/2017 09:18 PM 968 hierarchy.res
            02/04/2017 09:18 PM 245,248 hierarchyax.dll
            02/04/2017 09:18 PM 1,304 hierarchyax.exp
            02/04/2017 09:18 PM 6,140 hierarchyax.idl
            02/04/2017 09:18 PM 1,580 hierarchyax.lib
            02/04/2017 09:18 PM 8,060 hierarchyax.tlb
            02/05/2017 06:32 PM <DIR> iconengines
            02/05/2017 06:32 PM <DIR> imageformats
            12/01/2016 04:01 PM 15,360 libEGL.dll
            12/01/2016 04:01 PM 2,546,176 libGLESV2.dll
            02/04/2017 09:18 PM 137,058 main.obj
            02/04/2017 09:18 PM 8,467 moc_objects.cpp
            02/04/2017 09:18 PM 8,645 moc_objects.obj
            10/04/2013 11:58 PM 660,128 msvcp120.dll
            10/04/2013 11:58 PM 963,232 msvcr120.dll
            02/04/2017 09:18 PM 33,222 objects.obj
            09/25/2014 04:58 PM 17,593,856 opengl32sw.dll
            02/05/2017 06:32 PM <DIR> platforms
            02/05/2017 07:08 PM 20 qt.conf
            02/05/2017 06:32 PM 5,645,312 Qt5Core.dll
            12/01/2016 04:08 PM 5,937,152 Qt5Gui.dll
            12/01/2016 06:47 PM 317,440 Qt5Svg.dll
            12/01/2016 04:13 PM 5,518,848 Qt5Widgets.dll
            02/05/2017 06:32 PM <DIR> translations

            What could be the point being missed?

            A Qt Enthusiastic...

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hskoglund
              wrote on 5 Feb 2017, 14:53 last edited by
              #6

              Hi. I see you're using MSVC2013 64-bit version, I always have problems with using regsvr32 on a 64-bit .dll :-( For example see this stackoverflow discussion)

              Try recompiling the hierarchy example with MSVC2013 32-bit version. Also a qt.conf file shouldn't be needed. If you run into problems with regsvr32, you could try debugging it with ``SET QT_DEBUG_PLUGINS=1```, like this:

              C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
              elease\release>SET QT_DEBUG_PLUGINS=1
              
              C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
              elease\release>dbgview
              
              C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
              elease\release>regsvr32 hierarchyax.dll
              

              (To see the output download DbgView from here)

              T 1 Reply Last reply 5 Feb 2017, 15:17
              1
              • T Offline
                T Offline
                TheCrowKaka
                wrote on 5 Feb 2017, 15:13 last edited by
                #7

                Hello

                I tried the debugging. I got an output as shown here.
                [1356] QFactoryLoader::QFactoryLoader() checking directory path "C:/Windows/system32/platforms" ...
                [1356] This application failed to start because it could not find or load the Qt platform plugin "windows"
                [1356] in "".
                [1356]
                [1356] Reinstalling the application may fix this problem.

                Does it mean that it is searching for the platform plugins in the windows/system32 directory?

                I copied the platforms directory in the system32 directory and wow, it registered the dll.
                what is the way to avoid this coping of platforms directory?

                A Qt Enthusiastic...

                1 Reply Last reply
                0
                • H hskoglund
                  5 Feb 2017, 14:53

                  Hi. I see you're using MSVC2013 64-bit version, I always have problems with using regsvr32 on a 64-bit .dll :-( For example see this stackoverflow discussion)

                  Try recompiling the hierarchy example with MSVC2013 32-bit version. Also a qt.conf file shouldn't be needed. If you run into problems with regsvr32, you could try debugging it with ``SET QT_DEBUG_PLUGINS=1```, like this:

                  C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
                  elease\release>SET QT_DEBUG_PLUGINS=1
                  
                  C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
                  elease\release>dbgview
                  
                  C:\Qt\Examples\Qt-5.8\activeqt\build-hierarchy-Desktop_Qt_5_8_0_MSVC2015_32bit-R
                  elease\release>regsvr32 hierarchyax.dll
                  

                  (To see the output download DbgView from here)

                  T Offline
                  T Offline
                  TheCrowKaka
                  wrote on 5 Feb 2017, 15:17 last edited by
                  #8

                  @hskoglund

                  And even after the regsvr32 success, i still cannot see the reference in visual basic.

                  A Qt Enthusiastic...

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TheCrowKaka
                    wrote on 28 Feb 2017, 15:11 last edited by
                    #9

                    Hello hskoglund

                    So finally after a lot of trial and errors the hierarchy example worked for me only after i downloaded the Qt5.8 for MSVC15 32bit version.
                    When the dll was created.. all the steps happened just the way you had shown earlier.

                    Thanks for your help.

                    A Qt Enthusiastic...

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hskoglund
                      wrote on 1 Mar 2017, 13:33 last edited by
                      #10

                      👍👍👍👍

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved