Results 1 to 10 of 10

Thread: Qt and the Win32 API.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs down Qt and the Win32 API.

    Hello guys,

    Recently i've been asked to develop a wrapper between an existing application ("Coded" with Windev) and a device driver.
    The device driver documentation is very clear, and i've chosen to use a few Qt classes for that purpose.
    The problem is in one of the device driver API function, which requires a HWND as a parameter for it's "Start Up" function.
    Then, the supposedly passed HWND would get notified via posted messages of the advancement of the startup, and of the device state...

    i am totally off windows programming, it's been 7 years that i've only been coding cross-platform, or linux / unix exclusively... So i'm kind of stuck here.

    My first guess would be to create a QThread, and try to manufacture a structure as close as a HWND is, so it can receive the message. But seriously, i've no idea on how to do that...

    Can someone give me a clue, or help me a bit on this one please (Of course, i still want to avoid to use any Win32 specific code in the wrapper)?

    [EDIT]i forgot... The library i'm writing will act like a bridge and will not have any window... So i'm looking for any other way to get the posted messages to the HWND object.[/EDIT]
    Pierre.
    Last edited by hickscorp; 21st January 2010 at 16:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    I didn't quite understand what a "wrapper between" might be.
    You wrap something, not between things.

    I also am not sure if you mean realy a device driver, or more lib which works with a device driver.

    In any case, if you are working with a device driver on any level, it is system specific, so you might as well use system specific code, at least in the parts that are system specific.

    Under windows, you will have to create a message loop, if you want to process events.
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

    If there are no windows in the application, you wont have HWND to give, and you will have to use NULL.
    But if you make your own message loop, you can handle messages to "no windows" as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    Hello High Flyer, and thank you very much for your answer.

    Quote Originally Posted by high_flyer View Post
    I didn't quite understand what a "wrapper between" might be.
    You wrap something, not between things.
    I also am not sure if you mean realy a device driver, or more lib which works with a device driver.
    Right. i'm wrapping a DLL which provides access to a peripheral. i'm making a DLL itself which will make functions from the 1st DLL accessible from the Windev application.

    Quote Originally Posted by high_flyer View Post
    In any case, if you are working with a device driver on any level, it is system specific, so you might as well use system specific code, at least in the parts that are system specific.
    In this case, it's not the driver, as you pointed. It's a DLL provided with the driver, which provides I/O to a peripheral, but is coded to work only with windows. Too bad.

    Quote Originally Posted by high_flyer View Post
    Under windows, you will have to create a message loop, if you want to process events.
    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
    If there are no windows in the application, you wont have HWND to give, and you will have to use NULL.
    But if you make your own message loop, you can handle messages to "no windows" as well.
    i'm not sure i understand... How will the 3rd party API be able to send me messages if i'm giving it a NULL HWND?
    Let's say i create a message handler, how will i tell the 3rd party DLL to send the messages to this loop, since it's usually bound to the HWND object passed?

  4. #4
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt and the Win32 API.

    This is similar to (though more complex than) a problem on which I’m working. The HWND part is pretty simple.

    If you create and instantiate a class derived from QWidget, you can use QWidget::winId to get an HWND (assuming you’re sure you’re running under Windows, of course). It doesn’t matter that you don’t want to see the window... you just never show it. Use QWidget::winEvent to capture the messages.

  5. The following user says thank you to Coises for this useful post:

    hickscorp (23rd January 2010)

  6. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    It's a DLL provided with the driver, which provides I/O to a peripheral, but is coded to work only with windows. Too bad.
    If it is Windows driver with an API provided in Windows DLL so it will work only for Windows and rather any cross platform wrapper will not work because for other platforms you need to have different driver and I don't think that DLL will work anywhere else. I don't know exactly what Windev application means. Is it coded in C# (so using .NET) or in C/C++ using WinAPI? If it is using WinAPI than i think you don't need Qt as well, just code in WinAPI as you DLL uses WinAPI and your app uses WinAPI...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. The following user says thank you to faldzip for this useful post:

    hickscorp (23rd January 2010)

  8. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    i'm not sure i understand... How will the 3rd party API be able to send me messages if i'm giving it a NULL HWND?
    Usually you have to give a function pointer to a call back.
    There HWND can be null, and with your message pump you handle messages of type X and not on a window basis.
    (like for example handling SetTimer() in a console application)

    But I misunderstood your first post to some extent, and I too recommend to go the way Coises suggested.

    But putting the extra effort in cross platform wrapper only makes sense, if he driver is also available on other platforms, and, that it uses the same API it does under windows.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. The following user says thank you to high_flyer for this useful post:

    hickscorp (23rd January 2010)

  10. #7
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    Hello guys and thanks a lot for all these answers.

    i've kinda figured that out now, with all your help and digging into the Win32 API... Now the problem extends to this thread: http://www.qtcentre.org/threads/2747...n-In-a-library
    If you guys who helped me can be kind enough to have a look at the thread, i'll be eternally greatfull

    Thanks again to you 3!
    Me.

  11. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    Quote Originally Posted by high_flyer View Post
    But putting the extra effort in cross platform wrapper only makes sense, if he driver is also available on other platforms, and, that it uses the same API it does under windows.
    As it uses HWNDs I don't really think that it is mentioned to be used anywhere but on Windows. My suspicions are that this app is made for Windows only and this driver and it's library (in DLL) i provided for Windows then using Qt there is rather adding some needless dependency which is used to "translate" WinAPI to Qt and than "translate back" to WinAPI, just to use Qt's classes, structs and functions as they are more user friendly and you don't have to learn WinAPI much. I don't know how complicated is the main task which has to be done, but if it is not a really big one then learning and using WinAPI without Qt would be the proper idea. For me it looks like adding new functionality for Java-only project using C++, just because you don't know and don't want to learn some Java...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  12. The following user says thank you to faldzip for this useful post:

    hickscorp (23rd January 2010)

  13. #9
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    Quote Originally Posted by faldżip View Post
    As it uses HWNDs I don't really think that it is mentioned to be used anywhere but on Windows. My suspicions are that this app is made for Windows only and this driver and it's library (in DLL) i provided for Windows then using Qt there is rather adding some needless dependency which is used to "translate" WinAPI to Qt and than "translate back" to WinAPI, just to use Qt's classes, structs and functions as they are more user friendly and you don't have to learn WinAPI much. I don't know how complicated is the main task which has to be done, but if it is not a really big one then learning and using WinAPI without Qt would be the proper idea. For me it looks like adding new functionality for Java-only project using C++, just because you don't know and don't want to learn some Java...
    i have all this reflexion in mind already thanks. But the question wasn't about that at all. The "Wrapper" will have to do very complex things (Not only just wrapping things). Handwriting recognition, MICR reading and patterns recognition. That's why i choose Qt, because i want all my objects to be easily cross-platform... i've already wrote the abstraction class for the scanner wrappers (The whole complex thing will work with the abstract class), and i'm now trying to create as many derived classes as there are scanners used by the customer... All in the same library. Of course, if one of them is only providing an API which is highly Win32 oriented, the first thing i'm doing is looking for very generic drivers. Too bad for me, there are none for the one giving me the problem.

    Anyway, now the problem seem to more be about QCoreApplication and it's main processing loop, that's why i've posted the link to the other topic here: http://www.qtcentre.org/threads/2747...n-In-a-library .
    Thanks a lot for your efforts and time trying to sort things out
    Me.

  14. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and the Win32 API.

    Quote Originally Posted by hickscorp View Post
    i have all this reflexion in mind already thanks. But the question wasn't about that at all. The "Wrapper" will have to do very complex things (Not only just wrapping things). Handwriting recognition, MICR reading and patterns recognition. That's why i choose Qt, because i want all my objects to be easily cross-platform...
    What is the point in making cross-platform classes and mix them with WinAPI stuff in one library which depends on the Windows specific driver and library? I think that you should divide you project into two parts:
    1. Your library doing all you want, like pattern recognition etc with some public pure-C++ API (you know, using std::strings, iostreams or whatever). This library will use Qt and standard C++ libraries so it would be fully cross-platform.
    2. Now create wrapper for your driver and DLL which will be platform specific and will provide API that suits your previously created cross-platform library. In your case it will be written in C++ using WinAPI and will provide data for the library.

    In this case new platforms and scanners will require new "wrapper" and will always use that one cross-platform library but in your solution, new scanner will require writing new library if your library has crossplatform classes but placed in one library with platform and device specific stuff...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. how to use Qt dll in Win32 project
    By Fastman in forum Qt Programming
    Replies: 8
    Last Post: 10th July 2009, 13:16
  2. QT app on several win32 computers
    By mmickey in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2009, 12:42
  3. win32 api
    By weixj2003ld in forum Newbie
    Replies: 1
    Last Post: 17th April 2009, 08:46
  4. arg!!!! QProcess on win32
    By gfunk in forum Qt Programming
    Replies: 7
    Last Post: 27th January 2008, 19:40
  5. Qt Themes on win32? how?
    By Thaorius in forum Qt Programming
    Replies: 2
    Last Post: 2nd September 2007, 01:45

Tags for this Thread

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.