Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How to add third party library .DLL in QT project

    General and Desktop
    6
    12
    11924
    Loading More Posts
    • 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.
    • M
      m.sarfraz last edited by

      Hi,

      I want to add third party .dll file in my project. and call exposed function from qt program. I am running QT 5.4 on windows 8.1.

      "Add library" feature in QT opens a form. then asks for type of library (internal, external or system). if we pick external it goes to next screen but provides .lib and .a file as acceptable extensions NOT .DLL

      How can we add .dll in our QT project in windows environment and use it. (Call exposed functions of .DLL from QT program).

      Thanks
      Muhammad Sarfraz

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        Hi, welcome to devnet.

        To link to external library you either need the .dll, the .lib/.a and the header, in which case you use the above wizard, or use "QLibrary":http://doc.qt.io/qt-5/qlibrary.html to load the .dll dynamically and resolve entry points manually.

        1 Reply Last reply Reply Quote 0
        • M
          m.sarfraz last edited by

          Thanks Chris for your reply.

          In QT 5.4 this wizard has no option to select .DLL type of file. It is fixed to .a or .lib type.
          I am running QT 5.4 on Windows 8.1.

          Am I using wizard correctly or can it be a Bug in QT 5.4 environment ?

          Thanks
          Muhammad

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi and welcome to devnet,

            If you want to link against your 3rd party library, then it's either the lib or a files. You don't link against dlls

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • M
              m.sarfraz last edited by

              Hi SGaist,

              Thanks for your reply.

              Can you please tell me how to use third party .dll in QT ? any example ?

              Thanks
              Muhammad

              1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators last edited by

                if you use the wizard like already mentioned you link against this DLL file as an dependency.
                Meaning your application can't even start without it and automatically loads it if it's found or displays an error message if not.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply Reply Quote 0
                • M
                  m.sarfraz last edited by

                  How can i use third party .DLL ? any example?

                  1 Reply Last reply Reply Quote 0
                  • hskoglund
                    hskoglund last edited by

                    Hi, just tested using a 3rd party DLL with Qt, it's pretty straightforward:
                    I choose to test an old DLL present in Windows XP for the FreeCell game, called cards.dll, if you don't have Windows XP you can download the dll "here":http://www.dlldump.com/download-dll-files_new.php/dllfiles/C/cards.dll/5.1.2600.0/download.html The site looks suspicious but I checked, if you click to the right (Click Here to Download cards.zip) you'll get the exact same cards.dll that's in C:\Windows\System32 in Windows XP.

                    For this example I put cards.dll in C:\Downloads. Also you need to know about the function(s) you are calling, in this case I googled for a description of the functions inside cards.dll, I use 2: cdtInit and cdtDraw.

                    Create a new Widgets app, first insert CONFIG += c++11 in your .pro file to turn on C++11 features, then goto your mainwindow.cpp, insert these includes:
                    @
                    #include "QLibrary"
                    #include "QTimer"
                    #include "windows.h"
                    @

                    then below ui->setupUi(this); insert this fancy code:
                    @
                    ((int (WINAPI*)(int*,int*)) QLibrary("C:/Downloads/cards.dll").resolve("cdtInit"))(new int, new int);
                    QTimer* pTimer = new QTimer(this);
                    pTimer->start(500);
                    connect(pTimer,&QTimer::timeout,
                    {
                    auto GetDC = (int (WINAPI *)(int)) QLibrary("user32.dll").resolve("GetDC");
                    auto cdtDraw = (int (WINAPI *)(int,int,int,int,int,int)) QLibrary("C:/Downloads/cards.dll").resolve("cdtDraw");
                    cdtDraw(GetDC(0),rand() % 1000,rand() % 1000,rand() % 52,0,0);
                    });
                    @

                    If you do it right you'll get lots of cards drawn on your screen like this: !http://www.tripleboot.org/Pictures/DLLTest.png(Lots of cards)!

                    1 Reply Last reply Reply Quote 0
                    • A
                      alex_malyu last edited by

                      I just want to add that normally you do not use random 3rd party dll.
                      If you are legally allowed to use it you will have access to headers files you need and associated lib files or would be able to build them.

                      That means that you do not need to use QLibrary or in other way to resolve calls. you will include appropriate header and link against appropriate lib file
                      Dll and call functions like they were in your module. Dll will be loaded by your exe at runtime. You will have to provide it with your code.

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        I agree with the random part however, that technique is perfectly fine otherwise and Qt uses it for e.g. OpenSSL by default

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply Reply Quote 0
                        • M
                          m.sarfraz last edited by

                          Thanks for your reply Robot Herder, Ant Farmer and Mad Scientist.

                          Is there any difference if i want to use this .dll for mobile app (Android and Windows)?

                          for example can i use card.dll in Android app and get same results ?

                          Thanks and Regards

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            No you can't that dll uses Win32 specific API

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post