Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: QLibrary: how to download and check?

  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 21: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 

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

    Default Re: QLibrary: how to download and check?

    C:\Qt\errorString-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK_________\..\errorString\main.cpp :-1: error: C1902: ЌҐб®®вўҐвбвўРÒ ¤ЁбЇҐвзҐа* ÐŽ*§л ¤***ле Їа®Ја*¬¬л; Їа®ўҐам⥠гбв**®ў«Ґ**го Є®ЇЁо

    I have a library AtUsbHid.dll header atusbhid.h

    Qt Code:
    1. #ifndef _ATUSBHID_H_
    2. #define _ATUSBHID_H_
    3.  
    4. // Error codes.
    5. #define ERROR_USB_DEVICE_NOT_FOUND 0xE0000001
    6. #define ERROR_USB_DEVICE_NO_CAPABILITIES 0xE0000002
    7.  
    8. // name of the DLL to be loaded
    9. #define AT_USB_HID_DLL "AtUsbHid"
    10.  
    11. // Implement the DLL export/import mechanism and allow a C-written program
    12. // to use our DLL.
    13. #ifdef ATUSBHID_EXPORTS
    14. #define ATUSBHID_API extern "C" __declspec(dllexport)
    15. #else
    16. #define ATUSBHID_API extern "C" __declspec(dllimport)
    17. #endif
    18.  
    19.  
    20. // This macro function calls the C runtime's _beginthreadex function.
    21. // The C runtime library doesn't want to have any reliance on Windows' data
    22. // types such as HANDLE. This means that a Windows programmer needs to cast
    23. // values when using _beginthreadex. Since this is terribly inconvenient,
    24. // this macro has been created to perform the casting.
    25. typedef unsigned(__stdcall *PTHREAD_START)(void *);
    26.  
    27. #define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
    28. pvParam, fdwCreate, pdwThreadId) \
    29. ((HANDLE)_beginthreadex( \
    30. (void *) (psa), \
    31. (unsigned) (cbStack), \
    32. (PTHREAD_START) (pfnStartAddr), \
    33. (void *) (pvParam), \
    34. (unsigned) (fdwCreate), \
    35. (unsigned *)(pdwThreadId)))
    36.  
    37. // Allow applications not built with Microsoft Visual C++ to link with our DLL.
    38. #define STDCALL __stdcall
    39.  
    40. // These macros make calling our DLL functions through pointers easier.
    41. #define DECLARE_FUNCTION_POINTER(FUNC) PF_##FUNC lp##FUNC=NULL;
    42. #define LOAD_FUNCTION_POINTER(DLL,FUNC) lp##FUNC = (PF_##FUNC)GetProcAddress(DLL, #FUNC);
    43. #define ADDR_CHECK(FUNC) if (lp##FUNC == NULL) {fprintf(stderr,"%s\n", "Error: Cannot get address of function."); return FALSE;}
    44. #define DYNCALL(FUNC) lp##FUNC
    45.  
    46.  
    47. ///////////////////////////////////////////////////////////////////////////////
    48. typedef BOOLEAN (STDCALL *PF_findHidDevice)(const UINT VendorID, const UINT ProductID);
    49. typedef void (STDCALL *PF_closeDevice)(void);
    50. typedef BOOLEAN (STDCALL *PF_writeData)(UCHAR* buffer);
    51. typedef BOOLEAN (STDCALL *PF_readData)(UCHAR* buffer);
    52. typedef int (STDCALL *PF_hidRegisterDeviceNotification)(HWND hWnd);
    53. typedef void (STDCALL *PF_hidUnregisterDeviceNotification)(HWND hWnd);
    54. typedef int (STDCALL *PF_isMyDeviceNotification)(DWORD dwData);
    55. typedef BOOLEAN (STDCALL *PF_setFeature)(UCHAR* buffer);
    56. typedef int (STDCALL *PF_getFeatureReportLength)();
    57. typedef int (STDCALL *PF_getInputReportLength)();
    58. typedef int (STDCALL *PF_getOutputReportLength)();
    59.  
    60. ///////////////////////////////////////////////////////////////////////////////
    61.  
    62. // Exported functions prototypes.
    63.  
    64. ///////////////////////////////////////////////////////////////////////////////
    65. ATUSBHID_API BOOLEAN STDCALL findHidDevice(const UINT VendorID, const UINT ProductID);
    66.  
    67. // Closes the USB device and all handles before exiting the application.
    68. ATUSBHID_API void STDCALL closeDevice(void);
    69.  
    70. ATUSBHID_API BOOLEAN STDCALL writeData(UCHAR* buf);
    71.  
    72. ATUSBHID_API BOOLEAN STDCALL readData(UCHAR* buffer);
    73.  
    74. ATUSBHID_API int STDCALL hidRegisterDeviceNotification(HWND hWnd);
    75.  
    76. ATUSBHID_API void STDCALL hidUnregisterDeviceNotification(HWND hWnd);
    77.  
    78. ATUSBHID_API int STDCALL isMyDeviceNotification(DWORD dwData);
    79.  
    80. ATUSBHID_API BOOLEAN STDCALL setFeature(UCHAR *buffer);
    81.  
    82. ATUSBHID_API int STDCALL getFeatureReportLength(void);
    83.  
    84. ATUSBHID_API int STDCALL getOutputReportLength(void);
    85.  
    86. ATUSBHID_API int STDCALL getInputReportLength(void);
    87.  
    88. ///////////////////////////////////////////////////////////////////////////////
    89.  
    90. #ifndef ATUSBHID_EXPORTS
    91.  
    92.  
    93. DECLARE_FUNCTION_POINTER(findHidDevice);
    94. DECLARE_FUNCTION_POINTER(closeDevice);
    95. DECLARE_FUNCTION_POINTER(writeData);
    96. DECLARE_FUNCTION_POINTER(readData);
    97. DECLARE_FUNCTION_POINTER(hidRegisterDeviceNotification);
    98. DECLARE_FUNCTION_POINTER(hidUnregisterDeviceNotification);
    99. DECLARE_FUNCTION_POINTER(isMyDeviceNotification);
    100. DECLARE_FUNCTION_POINTER(setFeature);
    101. DECLARE_FUNCTION_POINTER(getFeatureReportLength)
    102. DECLARE_FUNCTION_POINTER(getOutputReportLength)
    103. DECLARE_FUNCTION_POINTER(getInputReportLength)
    104.  
    105. // this function call all function available in the DLL *
    106. static bool loadFuncPointers(HINSTANCE hLib)
    107. {
    108. LOAD_FUNCTION_POINTER(hLib, findHidDevice);
    109. ADDR_CHECK(findHidDevice);
    110.  
    111. LOAD_FUNCTION_POINTER(hLib, closeDevice);
    112. ADDR_CHECK(closeDevice);
    113.  
    114. LOAD_FUNCTION_POINTER(hLib, writeData);
    115. ADDR_CHECK(writeData);
    116.  
    117. LOAD_FUNCTION_POINTER(hLib, readData);
    118. ADDR_CHECK(readData);
    119.  
    120. LOAD_FUNCTION_POINTER(hLib, hidRegisterDeviceNotification);
    121. ADDR_CHECK(hidRegisterDeviceNotification);
    122.  
    123. LOAD_FUNCTION_POINTER(hLib, hidUnregisterDeviceNotification);
    124. ADDR_CHECK(hidUnregisterDeviceNotification);
    125.  
    126. LOAD_FUNCTION_POINTER(hLib, isMyDeviceNotification);
    127. ADDR_CHECK(isMyDeviceNotification);
    128.  
    129. LOAD_FUNCTION_POINTER(hLib, setFeature);
    130. ADDR_CHECK(setFeature);
    131.  
    132. LOAD_FUNCTION_POINTER(hLib, getOutputReportLength);
    133. ADDR_CHECK(getOutputReportLength);
    134.  
    135. LOAD_FUNCTION_POINTER(hLib, getInputReportLength);
    136. ADDR_CHECK(getInputReportLength);
    137.  
    138. LOAD_FUNCTION_POINTER(hLib, getFeatureReportLength);
    139. ADDR_CHECK(getFeatureReportLength);
    140.  
    141. return true;
    142. }
    143.  
    144. #endif
    145.  
    146. #endif // _ATUSBHID_H_
    To copy to clipboard, switch view to plain text mode 


    Added after 13 minutes:


    The console displays "No errors"
    Last edited by lucky_sever; 12th April 2012 at 22:14.

  10. #10
    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?

    The console displays "No errors"
    OK, this means the library has been loaded, and you have a function pointer to the "openDevice" method. So, it is working. From you r header file, it looks like all of the exports except for openDevice have function prototypes in the .h file. I do not have any idea how you use this library, so I cannot help you with that.

    These lines in the .h file:

    Qt Code:
    1. DECLARE_FUNCTION_POINTER(findHidDevice);
    2. DECLARE_FUNCTION_POINTER(closeDevice);
    3. //...
    To copy to clipboard, switch view to plain text mode 

    are declaring variables like this:

    Qt Code:
    1. PF_findHidDevice lpfindHidDevice = NULL;
    2. PF_closeDevice lpcloseDevice = NULL;
    3. // ...
    To copy to clipboard, switch view to plain text mode 
    So your Qt code, I think you need to do something like this after you load the library:

    Qt Code:
    1. lpfindHidDevice = qLib.resolve( "findHidDevice" );
    2. lpcloseDevice = qLib.resolve( "closeDevice" );
    3.  
    4. // etc.
    To copy to clipboard, switch view to plain text mode 

    To use one of these functions, you need to look at its signature in the .h file, and pass the correct arguments to it. For example, "findHidDevice" expects two arguments: an unsigned integer VendorID, and an unsigned integer ProductID. I assume you know what these are, so you can assign correct values to them. The DYNCALL() macro in the .h file allows you to call that method in your code like this:

    Qt Code:
    1. UINT vendorID = 123; // I made this up...
    2. UINT productID = 456; // and this too. You have to know the correct IDs when you call this method
    3. BOOLEAN bFound = DYNCALL(findHidDevice)( vendorID, productID );
    4.  
    5. if ( bFound == FALSE )
    6. // then it didn't find the device you were looking for
    7. else
    8. {
    9. // found it, now do something with it
    10. }
    To copy to clipboard, switch view to plain text mode 


    Added after 12 minutes:


    Google shows me this link for the Atmel USB Microcontrollers Application Note. This looks like the library you are using, so if you do not have this document, you should probably get it so you know how to use the library.
    Last edited by d_stranz; 12th April 2012 at 23:01.

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

    Default Re: QLibrary: how to download and check?

    This library is used for communication AtUsbHid.DLL Atmel microcontroller at90usb PC. The program connects to USB-device and communicates with the library.


    Added after 6 minutes:


    Thank you very much! I have this article, and even have a program written in Visual C + +. But I can not recompile it on the QT.
    Last edited by lucky_sever; 12th April 2012 at 23:13.

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

    Default Re: QLibrary: how to download and check?

    I'm doing right?

    Qt Code:
    1. #include "AtUsbHid.h"
    2.  
    3. #define DEFAULT_VID 0x03EB
    4. #define DEFAULT_PID 0x2013
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. vendorID = DEFAULT_VID;
    17. productID = DEFAULT_PID;
    18. }
    19.  
    20. void MainWindow::on_ConnectUsb_clicked()
    21. {
    22. //***********************************************************
    23. QLibrary hLib(AT_USB_HID_DLL);
    24. hLib.load();
    25.  
    26. if (!hLib.load())
    27. {
    28. QMessageBox::warning(this, tr("Error"),
    29. tr("Not found AtUsbHid.dll"),
    30. return;
    31. }
    32.  
    33. //***********************************************************
    34.  
    35. typedef void (*lpfindHidDevice)();
    36. typedef void (*lphidRegisterDeviceNotification)();
    37.  
    38. PF_findHidDevice lpfindHidDevice = NULL;
    39. PF_hidRegisterDeviceNotification lphidRegisterDeviceNotification = NULL;
    40.  
    41. lpfindHidDevice = hLib.resolve( "findHidDevice" );
    42. lphidRegisterDeviceNotification = hLib.resolve( "closeDevice" );
    43.  
    44. BOOLEAN bFound = DYNCALL(findHidDevice)( vendorID, productID );
    45. if ( bFound == FALSE )
    46. {
    47. qDebug ("Not DYNCALL findHidDevice");
    48. }
    49. else
    50. {
    51. qDebug ("DYNCALL findHidDevice");
    52. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    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: QLibrary: how to download and check?

    I would like to return to one of the earlier questions asked. Why are you loading the library runtime instead of linking to it at compile time? Do you have a .lib file corresponding to the DLL file you are using?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: QLibrary: how to download and check?

    I have only AtUsbHid.dll and AtUsbHid.h.

    And how to specify a reference to it at compile time?

  15. #15
    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: QLibrary: how to download and check?

    Quote Originally Posted by lucky_sever View Post
    I have only AtUsbHid.dll and AtUsbHid.h.
    You can probably recreate the import library using one of tools available for that task.

    And how to specify a reference to it at compile time?
    Add a LIBS += -Ldirectorycontainingthelibfile -lAtUsbHid entry in your project file. Then you can use all the functions directly in your code without QLibrary or similar solutions.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    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?

    You can probably recreate the import library using one of tools available for that task.
    Apparently Microsoft doesn't supply any.

    Here is a link to a CodeProject article that describes the process. It looks very painful, even for a simple library such as this one.

    I downloaded the distribution package from Atmel that the OP refers to, and indeed, there is no import library, just a DLL and header. The example code provided in the package uses LoadLibrary and runtime resolution of the linkages. Worse, the header file declares global variables in such a way that it can't be included in more than one source file without getting multiply-defined reference errors at link time. So you are faced with either putting all of your code that uses the library into a single source file, rewriting the header to remove the variable declarations, or ignoring it altogether and doing your own header. I would opt for this last option.

    Further, the use of the library is intricately linked to the Windows messaging system. It uses WM_DEVICECHANGE messages to manage communication between the program and the Atmel controller. Fortunately, I think QWidget::winEvent() can be used to intercept and handle these.

    And finally, it also looks like the library can be used to communicate with only one device at a time; none of the methods in the DLL have any reference to a device ID, so commands to send and receive data appear to interact with whatever device was last connected.

    Atmel is a major supplier of embedded controllers. It seems sort of embarrassing that their software offering is so primitive.


    Added after 7 minutes:


    I'm doing right?
    I know you are having a hard time getting started. You picked a difficult project to learn Qt, because this DLL uses techniques that are unusual in the Qt world.

    I have the example project from Atmel that uses this library (UsbHidDemoCode). I will convert this to a Qt project for you and post the code here. It is a pretty simple GUI. However, I do not have any way to test the code since I do not have the Atmel board. You will have to test that yourself.
    Last edited by d_stranz; 13th April 2012 at 17:02.

  17. #17
    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: QLibrary: how to download and check?

    Quote Originally Posted by d_stranz View Post
    Apparently Microsoft doesn't supply any.
    It doesn't have to be of Microsoft origin. This is a C library, so no name mangling is involved. I think some simple scanner that discovers symbol addresses should be enough.

    http://www.mingw.org/wiki/CreateImportLibraries
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLibrary: how to download and check?

    If the OP is using the MingW compiler then chances are it will Just Work(tm) without an import library as long as it sees the DLL. Exactly the same LIBS incantations.

  19. #19
    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?

    No, he's using Visual Studio. Anyway, I have duplicated the Atmel demo project in Qt using the run-time QLibrary loading, and it will probably work fine.

    @lucky_sever: In the attached ZIP file is a Visual Studio 2008 project that implements the Atmel UsbHidDemoCode project as a Qt version.

    Because I do not have an Atmel board, I cannot test the code completely. However, I have added an "emulation mode" that responds to commands in the same way that the Atmel project does. There is one line in the UsbHidDlg.cpp file that must be changed in order to turn off emulation mode:

    Qt Code:
    1. void CUsbHidDlg::showEvent( QShowEvent * pEvent )
    2. {
    3. // TESTING ONLY - remove this when a live board is present (or change "true" to "false")
    4. mpController->setEmulating( true );
    5.  
    6. if ( mpController->initialize( "AtUSBHid.dll" ) )
    7. mpConnectionStatusCtrl->setText( "Library loaded" );
    8. else
    9. mpConnectionStatusCtrl->setText( "Library load failed" );
    10. }
    To copy to clipboard, switch view to plain text mode 

    The Atmel project mixed up communication with the board and the GUI dialog. I have split this into two classes: CUSBHidDlg and CUSBHidController.

    CUSBHidDlg is just the user interface. It does not know anything about the Atmel library. It creates an instance of CUSBHidController, which is the class that communicates with the board through the Atmel DLL. It is a QWidget-based class, and emits status and device connection signals.

    Because the Atmel library uses the Windows WM_DEVICECHANGE message to manage some communication with the board and operating system, it was necessary to override the QWidget::winEvent() method in CUSBHidController. This new code watches for the Atmel board being connected or disconnect from its USB port; but otherwise simply passes all other Windows messages along to Qt for handling.

    The ZIP file contains a complete project. Unzip it into a new directory to build it. You might have to change some of the VC++ project settings to make sure it finds the Qt header and library files correctly. Make sure that the Qt DLLs are in your PATH environment so the exe can find them at run time.

    I have not put too many comments into the code. Most of the methods are small and very similar to the Atmel demo code. If you have any questions, please ask.

    QtAtUSBHidDemo.zip

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

    Default Re: QLibrary: how to download and check?

    Excellent! Excellent! Excellent! Everything works: connects, receives and sends data.

    I could not write this! Tell me, please, and whether such a program to move to the Tablet PC on the android with slight modifications?


    Added after 37 minutes:


    Here are just at the close of the application in debug mode segfault.
    And wrote an unused variable closeDevice.
    Qt Code:
    1. DYNCALL (closeDevice) ();
    To copy to clipboard, switch view to plain text mode 


    Added after 23 minutes:


    warning: unused variable 'result'
    Swears on this line!

    Qt Code:
    1. int result = DYNCALL (hidRegisterDeviceNotification) (winId ());
    To copy to clipboard, switch view to plain text mode 

    You do not think I'm not complaining about the application, but only a share.
    Last edited by lucky_sever; 14th April 2012 at 13:01.

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, 10:47
  2. QLibrary
    By Amita in forum Qt Programming
    Replies: 10
    Last Post: 27th July 2011, 16:35
  3. How to use QLibrary?
    By digog in forum Newbie
    Replies: 22
    Last Post: 5th November 2010, 19:01
  4. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 15:03
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 13: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.