[Qt-interest] Raw input API / hInstance from inside Qt
Wolfgang Pausch
Wolfgang.Pausch at uibk.ac.at
Sat Feb 20 16:26:50 CET 2010
Hello,
I want to use the Raw Input API
http://msdn.microsoft.com/en-us/library/dd458635(VS.85).aspx inside a Qt
application. The reason for this is that I have to do some things with
multiple keyboards attached to the same computer (if details about what I want
to do are relevent, see at the end of the mail).
Ok, in order to receive events I have to call RegisterRawInputDevices. This
function needs arguments of type RAWINPUTDEVICE, which need a handle to a
Windows-Window. Fortunately, I found out that I can use so-called message only
windows for this, which seem to be some kind of window without the window, just
for event-processing.
In order to use them, I have to call CreateWindowEx. In order to use
CreateWindowEx, I have to register a windows class using RegisterClassEx. Now,
the latter needs a so called hInstance.
As far as I get it, usually you get such a hInstance as a parameter for WinMain.
But, in my Qt application I come from an ordinary main function. I simply
don´t have a WinMain.
So now I wonder: How can I use the Raw Input API from inside a Qt application?
Is there a way to obtain the hInstance from inside Qt?
Or is there another way for dealing with multiple external keyboards from inside
Qt?
(what I have to do is listening to them, getting the information which key was
pressed and especially on which of the keyboards it was pressed; thus I need
information like "the current key event was key x and came from the same
keyboard like the key event some minutes ago").
Thanks for any help,
Wolfgang
PS: I found some hints like this one
http://blog.m-ri.de/index.php/2007/12/12/die-unsitte-immer-getmodulehandlenull-fuer-hinstance-in-createwindow-und-registerclass-zu-verwenden/
containing the code snipped
HINSTANCE Get_hInstance()
{
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery(Get_hInstance, &mbi, sizeof(mbi));
return reinterpret_cast<HINSTANCE>(mbi.AllocationBase);
}
but (1) it does not compile (some forbidden cast) and (2) I don´t know wether I
should trust it.
More information about the Qt-interest-old
mailing list