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 Qt DLL usable from VB
QtWS25 Last Chance

Create Qt DLL usable from VB

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.12dllvba
6 Posts 2 Posters 1.4k 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.
  • B Offline
    B Offline
    Bastien
    wrote on 15 Nov 2018, 14:40 last edited by Bastien
    #1

    Hi,
    I try to create a Qt QLL who can be used from VB script.
    I create a lbrary Qt project.
    Here is my test.cpp:

    #include "test.h"
    
    DWORD __stdcall DllRegisterServer() {
        return 0;
    }
    
    DWORD __stdcall DllUnregisterServer() {
        return 0;
    }
    
    DWORD __stdcall runApp() {
        return 0;
    }
    

    Here is my test.h:

    #ifndef TEST_H
    #define TEST_H
    
    #include <windows.h>
    
    extern "C" DWORD __stdcall DllRegisterServer();
    extern "C" DWORD __stdcall DllUnregisterServer();
    extern "C" DWORD __stdcall runApp();
    
    #endif // TEST_H
    
    

    And here is my .h file:

    
    TARGET = testapp
    TEMPLATE = lib
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    
    CONFIG += c++11
    
    SOURCES += \
        test.cpp
    
    HEADERS += \
        test.h
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    My Dll build with success and with no error.
    I can execute the command regsvr32 on my dll with success.
    But from my VB script I can't call runApp() function.
    Vba error when i call the dll:
    0_1542292660798_error_qt_dll_vba.PNG

    My VB script:

    Option Explicit
    
    Public Declare PtrSafe Function runApp Lib "C:\Users\212721485\Documents\build-Qtdll_test-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\debug\Qtdll_test.dll" () As LongPtr
    
    Public Sub testRunApp()
        Dim lRetCode As LongPtr
        lRetCode = runApp
        MsgBox "runApp a retourné le code " & lRetCode, vbOKOnly Or vbSystemModal Or vbInformation, "test de DLL"
    End Sub
    

    This code works fine in Visual Studio but not in QtCreator... Why ?

    J 1 Reply Last reply 15 Nov 2018, 15:03
    0
    • B Bastien
      15 Nov 2018, 14:40

      Hi,
      I try to create a Qt QLL who can be used from VB script.
      I create a lbrary Qt project.
      Here is my test.cpp:

      #include "test.h"
      
      DWORD __stdcall DllRegisterServer() {
          return 0;
      }
      
      DWORD __stdcall DllUnregisterServer() {
          return 0;
      }
      
      DWORD __stdcall runApp() {
          return 0;
      }
      

      Here is my test.h:

      #ifndef TEST_H
      #define TEST_H
      
      #include <windows.h>
      
      extern "C" DWORD __stdcall DllRegisterServer();
      extern "C" DWORD __stdcall DllUnregisterServer();
      extern "C" DWORD __stdcall runApp();
      
      #endif // TEST_H
      
      

      And here is my .h file:

      
      TARGET = testapp
      TEMPLATE = lib
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      
      CONFIG += c++11
      
      SOURCES += \
          test.cpp
      
      HEADERS += \
          test.h
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      

      My Dll build with success and with no error.
      I can execute the command regsvr32 on my dll with success.
      But from my VB script I can't call runApp() function.
      Vba error when i call the dll:
      0_1542292660798_error_qt_dll_vba.PNG

      My VB script:

      Option Explicit
      
      Public Declare PtrSafe Function runApp Lib "C:\Users\212721485\Documents\build-Qtdll_test-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\debug\Qtdll_test.dll" () As LongPtr
      
      Public Sub testRunApp()
          Dim lRetCode As LongPtr
          lRetCode = runApp
          MsgBox "runApp a retourné le code " & lRetCode, vbOKOnly Or vbSystemModal Or vbInformation, "test de DLL"
      End Sub
      

      This code works fine in Visual Studio but not in QtCreator... Why ?

      J Offline
      J Offline
      JonB
      wrote on 15 Nov 2018, 15:03 last edited by
      #2

      @Bastien
      Your error message, which is shown truncated, shows a full path name, and a "file not found" message:

      • What is the full path in the message, and does it exist?
      • I don't know, but if it is a DLL, and if that DLL does exist but it has dependencies on other DLLs which are not found, might that give the same error message? In which case, maybe the path where it is set to search for additional DLLs is different within VS than outside, and that is why it only works from VS?
      B 1 Reply Last reply 15 Nov 2018, 15:30
      0
      • J JonB
        15 Nov 2018, 15:03

        @Bastien
        Your error message, which is shown truncated, shows a full path name, and a "file not found" message:

        • What is the full path in the message, and does it exist?
        • I don't know, but if it is a DLL, and if that DLL does exist but it has dependencies on other DLLs which are not found, might that give the same error message? In which case, maybe the path where it is set to search for additional DLLs is different within VS than outside, and that is why it only works from VS?
        B Offline
        B Offline
        Bastien
        wrote on 15 Nov 2018, 15:30 last edited by
        #3

        @JonB
        My full path is good.
        And my dll has only Windows.h dependency, this library is contained by default.
        The same code in Visual Studio work fine but not in Qt Creator.
        I think that it's because of build options.

        J 1 Reply Last reply 15 Nov 2018, 15:54
        0
        • B Bastien
          15 Nov 2018, 15:30

          @JonB
          My full path is good.
          And my dll has only Windows.h dependency, this library is contained by default.
          The same code in Visual Studio work fine but not in Qt Creator.
          I think that it's because of build options.

          J Offline
          J Offline
          JonB
          wrote on 15 Nov 2018, 15:54 last edited by JonB
          #4

          @Bastien

          The same code in Visual Studio work fine but not in Qt Creator.

          And when you build it in Visual Studio you are using the MinGW compiler, not the MSVC one, just like you show you are using from Qt Creator, right?

          B 1 Reply Last reply 16 Nov 2018, 10:23
          0
          • J JonB
            15 Nov 2018, 15:54

            @Bastien

            The same code in Visual Studio work fine but not in Qt Creator.

            And when you build it in Visual Studio you are using the MinGW compiler, not the MSVC one, just like you show you are using from Qt Creator, right?

            B Offline
            B Offline
            Bastien
            wrote on 16 Nov 2018, 10:23 last edited by Bastien
            #5

            @JonB
            I build with MinGW on Qt Creator. And when I use DLL, I've the error.

            J 1 Reply Last reply 16 Nov 2018, 11:46
            0
            • B Bastien
              16 Nov 2018, 10:23

              @JonB
              I build with MinGW on Qt Creator. And when I use DLL, I've the error.

              J Offline
              J Offline
              JonB
              wrote on 16 Nov 2018, 11:46 last edited by JonB
              #6

              @Bastien

              I build with MinGW on Qt Creator. And when I use DLL, I've the error.

              I didn't ask you that. I know that. That's why I asked you:

              And when you build it in Visual Studio you are using the MinGW compiler, not the MSVC one, just like you show you are using from Qt Creator, right?

              So I asked you what compiler you are using from Visual Studio, not Qt Creator.

              Having to make a guess and assuming you use MinGW from Qt Creator but MSVC from VS, I imagine that is precisely the answer to your:

              This code works fine in Visual Studio but not in QtCreator... Why ?

              1 Reply Last reply
              2

              6/6

              16 Nov 2018, 11:46

              • Login

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