Results 1 to 20 of 25

Thread: QLibrary: how to download and check?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Question QLibrary: how to download and check?

    There are some programs in C++

    Qt Code:
    1. #include <cstdlib>
    2. #include <iostream>
    3. #include <windows.h>
    4. #include "AtUsbHid.h"
    5.  
    6. using namespace std;
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. HINSTANCE hLib = NULL;
    11. hLib =LoadLibrary(AT_USB_HID_DLL);
    12. if(hLib == NULL){
    13. cout << "boing\n";
    14. }
    15. loadFuncPointers(hLib);
    16.  
    17. DYNCALL(findHidDevice)(Vid, Pid);
    18. DYNCALL(hidRegisterDeviceNotification)((m_hWnd));
    19.  
    20. system("PAUSE");
    21. return EXIT_SUCCESS;
    22. }
    To copy to clipboard, switch view to plain text mode 

    This realization is already on the QT. What am I doing wrong?

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QLibrary>
    4. #include <QMessageBox>
    5. #include <cstdlib>
    6. #include <stdio.h>
    7. #include <conio.h>
    8. #include <windows.h>
    9. #include <stddef.h>
    10. #include <windowsx.h>
    11.  
    12. // Include Atmel Hid Usb
    13. #include "AtUsbHid.h"
    14.  
    15. #define DEFAULT_VID 0x03EB
    16. #define DEFAULT_PID 0x2013
    17.  
    18.  
    19.  
    20. MainWindow::MainWindow(QWidget *parent) :
    21. QMainWindow(parent),
    22. ui(new Ui::MainWindow)
    23. {
    24. ui->setupUi(this);
    25.  
    26. }
    27.  
    28. MainWindow::~MainWindow()
    29. {
    30. delete ui;
    31.  
    32. Vid = DEFAULT_VID;
    33. Pid = DEFAULT_PID;
    34. }
    35.  
    36.  
    37.  
    38. void MainWindow::on_ConnectUsb_clicked()
    39. {
    40. QLibrary hLib(AT_USB_HID_DLL);
    41. hLib.load();
    42.  
    43. if (!hLib.load())
    44. {
    45. QMessageBox::warning(this, tr("Error"),
    46. tr("Not found AtUsbHid.dll"),
    47. return;
    48. }
    49. //***********************************************************
    50. typedef void (*func)();
    51. func PF_findHidDevice = (func) hLib.resolve("findHidDevice)(Vid, Pid)");
    52. if (!PF_findHidDevice)
    53. {
    54. qDebug ("!!!!!!!!findHidDevice");
    55. return;
    56. }
    57.  
    58.  
    59. typedef void (*func)();
    60. func PF_hidRegisterDeviceNotification = (func) hLib.resolve("hidRegisterDeviceNotification");
    61. if (!PF_hidRegisterDeviceNotification)
    62. {
    63. qDebug ("!!!!!!!!hidRegisterDeviceNotification");
    64. return;
    65. }
    66. //***********************************************************
    67. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    Have you read the QLibrary documentation? From the docs:

    The symbol must be exported as a C function from the library for resolve() to work. This means that the function must be wrapped in an extern "C" block if the library is compiled with a C++ compiler. On Windows, this also requires the use of a dllexport macro; see resolve() for the details of how this is done.
    Do you know anything about your library? Is it a C or a C++ library?

    What do you see when you look at it using the Visual Studio "dumpbin" tool? (Start a Visual Studio command window, cd to your dll folder, and type "dumpbin /EXPORTS AtUsbHid.dll"). This will show you the names of all of the exported classes and methods in the DLL. If you see things like this (from the Qwt 6.0 DLL):

    ?pinPoint@QwtSymbol@@QBE?AVQPointF@@XZ

    then this means your library is a C++ library and has C++ mangled names. If you see something like this (from pgort90.dll, in the Visual Studio distribution):

    IrtAutoSweepA

    then this means it is a C library, or that the symbols in it were exported using the extern "C" declaration described in the docs.

  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    library C++

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    OK, then try using resolve() with one of the mangled names you see in that dump, and see if that succeeds.

  5. #5
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    So I try to resolve (), the above code. But something does not work.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    Is there some reason why you hve to load this DLL at run time? Don't you have an import library (.lib) that you can link to, so the DLL can be loaded automatically when the program runs? You have the header file (.h), so why not use the .lib at link time?

    And did you look at the value return by the QLibrary::errorString() method to see what it says when the resolve() call fails?
    Last edited by d_stranz; 12th April 2012 at 20:04.

  7. #7
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    dumpbin.exe /exports

    Qt Code:
    1. Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
    2. Copyright (C) Microsoft Corporation. All rights reserved.
    3.  
    4.  
    5. Dump of file AtUsbHid.dll
    6.  
    7. File Type: DLL
    8.  
    9. Section contains the following exports for AtUsbHid.dll
    10.  
    11. 00000000 characteristics
    12. 479752C1 time date stamp Wed Jan 23 16:44:17 2008
    13. 0.00 version
    14. 1 ordinal base
    15. 21 number of functions
    16. 21 number of names
    17.  
    18. ordinal hint RVA name
    19.  
    20. 2 0 0000198D closeDevice
    21. 3 1 000011CF findHidDevice
    22. 4 2 00002103 getFeatureReportLength
    23. 5 3 000020F3 getInputReportLength
    24. 6 4 000020E3 getOutputReportLength
    25. 7 5 00001EB0 getch
    26. 8 6 00001FA0 hidRegisterDeviceNotification
    27. 9 7 00001F8F hidUnregisterDeviceNotification
    28. 10 8 00001FFD isMyDeviceNotification
    29. 11 9 00001000 openDevice
    30. 12 A 00001E62 putch
    31. 13 B 00001CE5 readContinuous
    32. 14 C 00001D1F readData
    33. 15 D 00001C13 readStandard
    34. 16 E 0000204D setFeature
    35. 17 F 00001AE7 setReportContinuous
    36. 18 10 00001F63 setTxPeriod
    37. 1 11 00001DED updateFeatureBytes
    38. 19 12 00001D2F writeContinuous
    39. 20 13 00001DDD writeData
    40. 21 14 00001B1D writeStandard
    41.  
    42. Summary
    43.  
    44. 5000 .data
    45. 2000 .rdata
    46. 1000 .reloc
    47. 1000 .rsrc
    48. 8000 .text
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLibrary: how to download and check?

    This is a C library, not a C++ library.

    Create a Qt Console Application, and insert this code in main(). What do you see when this code runs?

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QLibrary>
    3. #include <iostream>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9.  
    10. QLibrary qLib( "AtUsbHid.dll" );
    11. if ( qLib.load() )
    12. {
    13. void * func = qLib.resolve( "openDevice" );
    14. if ( 0 == func )
    15. std::cout << qLib.errorString().toStdString() << std::endl;
    16. else
    17. std::cout << "No errors" << std::endl;
    18. }
    19. else
    20. std::cout << qLib.errorString().toStdString() << std::endl;
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to check the file to download from ftp site exists ?
    By nikhilqt in forum Qt Programming
    Replies: 29
    Last Post: 8th November 2014, 09:47
  2. QLibrary
    By Amita in forum Qt Programming
    Replies: 10
    Last Post: 27th July 2011, 15:35
  3. How to use QLibrary?
    By digog in forum Newbie
    Replies: 22
    Last Post: 5th November 2010, 18:01
  4. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

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.