Results 1 to 5 of 5

Thread: How to use dll on Windows (2)

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How to use dll on Windows (2)

    I have a similar request as Merry in a previous post today.

    As this post was not answered I would like to be a bit more precise at least concerning my problem.

    Let's say I am writing an application using QT4 that is supposed to use the driver dll from a third vendor hardware device. The device comes with a .dll file, with a .lib file and with a .h file describing the driver interface. I have no possibility to recompile the .dll and the .lib files as they come as is, with the hardware device.

    For example let's take a fictive USB device implementing some leds. The driver allows the driving of it led's and comes with 3 files: ledviausb.dll, ledviausb.lib and ledviausb.h (see attachement)

    My question is to know how to integrate this into my QT4 project ?

    First I suppose that I would need to specify the .lib file in the project file ?
    Qt Code:
    1. LIBS += driver/ledviausb.lib
    2. INCLUDEPATH += driver
    To copy to clipboard, switch view to plain text mode 

    Than I would need to address it from my application ?

    Qt Code:
    1. #include "ledviausb.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7. CLEDviaUSB*test = new CLEDviaUSB();
    8. test->OpenDriver(0);
    9. test->SwitchOnLed(0,1);
    10. test->SwitchOnLed(0,2);
    11. return 0;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Do I need to rewrite the .h file to follow some QT4 specifications, because currently the compilation would give me something like:

    1>LINK : debug\dll_test_app.exe not found or not built by the last incremental link; performing full link
    1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: short __stdcall CLEDviaUSB::SwitchOnLed(unsigned char,short)" (__imp_?SwitchOnLed@CLEDviaUSB@@QAGFEF@Z) referenced in function _main
    1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: short __thiscall CLEDviaUSB::OpenDriver(unsigned char)" (__imp_?OpenDriver@CLEDviaUSB@@QAEFE@Z) referenced in function _main
    1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall CLEDviaUSB::CLEDviaUSB(void)" (__imp_??0CLEDviaUSB@@QAE@XZ) referenced in function _main
    1>debug\dll_test_app.exe : fatal error LNK1120: 3 unresolved externals
    1>Build log was saved at "file://c:\tmp\canmonitor\lab\dll_test_app\debug\BuildLog. htm"
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use dll on Windows (2)

    Let's see... according to me you need to add the following to your project file:
    txt Code:
    1. LIBS+=-Ldriver -lledviausb
    2.  
    3. HEADERS+=ledviausb.h
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to use dll on Windows (2)

    Well I am getting the same kind of linker errors:

    I do not understand anyway what would have been the difference under windows between

    LIBS += driver/ledviausb.lib
    and
    LIBS+=-Ldriver -lledviausb

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use dll on Windows (2)

    Was the library built for the same compiler you are using to compile your code? Maybe the name mangling mechanism is different?

  5. #5
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use dll on Windows (2)

    Is the header right? It may have an import error.

    Why don't you try to use dinamic linking? You do not need any header as far as i know but it is more difficult to use. The dinamic linking is done using QLibrary (Check it on the Qt Assistant).

Similar Threads

  1. Windows not appearing in XP.
    By beardybloke in forum Qt Programming
    Replies: 7
    Last Post: 24th October 2007, 17:32
  2. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  3. qt and mingw can not run on windows 98?
    By evewei in forum Installation and Deployment
    Replies: 4
    Last Post: 26th June 2006, 09:22
  4. MDI windows without QWorkspace
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 17:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.