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. Load Vb6 DLL Function
Forum Updated to NodeBB v4.3 + New Features

Load Vb6 DLL Function

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 3.3k Views 2 Watching
  • 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.
  • newbieQTDevN newbieQTDev

    Hi.
    I need to load a vb6 dll and run a function.
    This is an example where the function return a int but i want return a vb6 string how i do?

    #include <QCoreApplication>
    #include <QLibrary>
    #include <QDebug>
    
    typedef int (*call_func)();
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        QLibrary library( "C:\\Windows\\SysWOW64\\myDLL.dll" );
        library.load();
        if( !library.isLoaded() )
        {
            qDebug() << "Cannot load library.";
            return 0;
        }
        else qDebug()<<"I have load a library";
        call_func func = (call_func)library.resolve( "myIntFunction" );
        if( func)
        {
            qDebug()<<  func() << endl;
        } else qDebug() << "I not call function"<<endl;
    
        return a.exec();
    }
    
    

    Every help is appreciated. Thanks

    kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #5

    Something which @aha_1980's comment reminded me of ... you could in principle decode the decorated name from the binary. I will explain how if it gets to this, however it's much simpler if you have docs or otherwise information what's the C equivalent of the VB types.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    1
    • newbieQTDevN Offline
      newbieQTDevN Offline
      newbieQTDev
      wrote on last edited by
      #6

      Thanks for all.
      I will try to recover the documentation of the dll. I found some information about the conversion between the vb and c ++ data types.
      The equivalent type should be BSTR.
      Unraveling Strings in Visual C++
      My work scenario is quite strange. I have to call in C ++ (QT) some functions of a dll written for vb6. I am migrating an application from vb6 to C ++ (QT). My vb6 application uses the dll. Then i will include the functionality of the dll in my C ++ application (QT)

      1 Reply Last reply
      0
      • newbieQTDevN Offline
        newbieQTDevN Offline
        newbieQTDev
        wrote on last edited by
        #7

        As suggested by kshegunov I found the prototype of the function. this is

        STDMETHOD(get_SoftwareCode)(/*[out, retval]*/ BSTR *pVal);
        

        Which is the right method for the call?
        Thanks

        kshegunovK 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #8

          Hi
          Does the documentation mention who has ownership of the pVal?

          Anyway, you can try
          QString string("WHATEVER");
          BSTR bstr = SysAllocString(string.utf16());
          // use...
          SysFreeString(bstr); // unless DLL owns it..

          Notice this is native API and not Qt. So you might need extra includes
          and/or link to libs.

          Note that it seems to be other way. you call the DLL and it put data in the pVal.
          In that case, you might need t know maximum it needs.

          hskoglundH 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            Does the documentation mention who has ownership of the pVal?

            Anyway, you can try
            QString string("WHATEVER");
            BSTR bstr = SysAllocString(string.utf16());
            // use...
            SysFreeString(bstr); // unless DLL owns it..

            Notice this is native API and not Qt. So you might need extra includes
            and/or link to libs.

            Note that it seems to be other way. you call the DLL and it put data in the pVal.
            In that case, you might need t know maximum it needs.

            hskoglundH Online
            hskoglundH Online
            hskoglund
            wrote on last edited by
            #9

            @mrjj For an [out] COM BSTR, the caller of the function (i.e. Qt, not VB6) assumes responsibility of the memory management for the BSTR MSDN doc

            mrjjM 1 Reply Last reply
            4
            • hskoglundH hskoglund

              @mrjj For an [out] COM BSTR, the caller of the function (i.e. Qt, not VB6) assumes responsibility of the memory management for the BSTR MSDN doc

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @hskoglund
              haha cool you answered. i was actually thinking of you as if anyone knew what vb6 likes in 2018
              it might be you :)
              Yes so get_SoftwareCode wants a buffer and the caller must free it.
              Do you know a Qt way of constructing a BSTR besides the SysAllocString ?
              Im afraid the details escapes me after a decade ;)

              hskoglundH 1 Reply Last reply
              0
              • mrjjM mrjj

                @hskoglund
                haha cool you answered. i was actually thinking of you as if anyone knew what vb6 likes in 2018
                it might be you :)
                Yes so get_SoftwareCode wants a buffer and the caller must free it.
                Do you know a Qt way of constructing a BSTR besides the SysAllocString ?
                Im afraid the details escapes me after a decade ;)

                hskoglundH Online
                hskoglundH Online
                hskoglund
                wrote on last edited by
                #11

                @mrjj Had a look inside Qt's sources, found this function in qt-everywhere-src-5.10.1/qtbase/src/plugins/platforms/windows/accessible/comutils.h:

                BSTR QStringToBSTR(const QString &str)
                {
                    return SysAllocStringLen(reinterpret_cast<const OLECHAR *>(str.unicode()), UINT(str.length()));
                }
                
                mrjjM 1 Reply Last reply
                3
                • hskoglundH hskoglund

                  @mrjj Had a look inside Qt's sources, found this function in qt-everywhere-src-5.10.1/qtbase/src/plugins/platforms/windows/accessible/comutils.h:

                  BSTR QStringToBSTR(const QString &str)
                  {
                      return SysAllocStringLen(reinterpret_cast<const OLECHAR *>(str.unicode()), UINT(str.length()));
                  }
                  
                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  @hskoglund
                  Oh, good found. That should make it just work !

                  1 Reply Last reply
                  0
                  • newbieQTDevN newbieQTDev

                    As suggested by kshegunov I found the prototype of the function. this is

                    STDMETHOD(get_SoftwareCode)(/*[out, retval]*/ BSTR *pVal);
                    

                    Which is the right method for the call?
                    Thanks

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #13

                    @newbieQTDev said in Load Vb6 DLL Function:

                    STDMETHOD(get_SoftwareCode)(/*[out, retval]*/ BSTR *pVal);
                    

                    This is a method definition, according to MSDN, which means it applies to an object, so you also need to have the actual object to use it.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • newbieQTDevN Offline
                      newbieQTDevN Offline
                      newbieQTDev
                      wrote on last edited by
                      #14

                      Hi kshegunov.
                      I am sorry.
                      I may not have explained my problem well.
                      I'm trying to use a dll that was written using COM technology. It was written in C but to be used in VB6.
                      The signature of the function I inserted in the post is one of the many methods that the dll provides. After your consideration maybe the code I used is not appropriate to my case?

                      1 Reply Last reply
                      0

                      • Login

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