Why do you need to?
Why do you need to?
What functions are you trying to use? Most already have thunks, so you can just call them directly.
Because the rest of the C app needs HMODULE user32.Why do you need to?
Qt Code:
// Return 0 if rawinput is not available HMODULE user32 = LoadLibrary("user32.dll"); if (!user32) return 0; _RRID = (pRegisterRawInputDevices)GetProcAddress(user32,"RegisterRawInputDevices"); if (!_RRID) return 0; _GRIDL = (pGetRawInputDeviceList)GetProcAddress(user32,"GetRawInputDeviceList"); if (!_GRIDL) return 0; _GRIDIA = (pGetRawInputDeviceInfoA)GetProcAddress(user32,"GetRawInputDeviceInfoA"); if (!_GRIDIA) return 0; _GRID = (pGetRawInputData)GetProcAddress(user32,"GetRawInputData"); if (!_GRID) return 0;To copy to clipboard, switch view to plain text mode
The library having been loaded by the pe loader already (quite possibly the case) will not make LoadLibrary fail. Again, what does GetLastError() say?
In a Windows application, I can just use RegisterRawInputDevices(), I've never needed to do LoadLibrary/GetProcAddress, as they are standard functions.
This is why I'm confused. It's a standard library.
I'm thinking that this code was originally written to allow an assembly program to use the interface too (meaning it's probably quite old). Assembly modules carry no implied dependencies, so the linker does not automatically bind to any external modules.
user32.dll should already be loaded and the msdn documentation doesn't actually specify what happens if you call LoadLibrary on a dll which is already loaded, though I see no reason why it would not work ok. Did you ever try using GetLastError ?
You can always try using GetModuleHandle to get the handle to the already loaded dll if you really do want to use GetProcAddress. (though I do agree with squidge that this really isn't necessary).
Chris.
If there is a better way I would definitely go for it.You can always try using GetModuleHandle to get the handle to the already loaded dll if you really do want to use GetProcAddress.
Yes:Did you ever try using GetLastError ?
Qt Code:
qDebug() << init_raw_mouse(1, 0, 1) // Outputs 0; qDebug() << GetLastError(); // Outputs 0To copy to clipboard, switch view to plain text mode
Here they say that if I recompile QT passing -D _WIN32_WINNT=0×501 as arguments, I could filter WM_INPUT messages.
But I still would have to use that C file for the rest of the implementation(to get the different input's and their respective x & y axis).
How can I rebuild QT? Can that happen trough QtCreator? I have VS2010, but don't use it.
:
Added after 4 minutes
So if I included windows.h I could trim the code a bit? (I have no idea on Win32 programming.)
:
Added after 6 minutes
The website I downloaded the demo was here. I'm including the whole app in the attachment.
Last edited by been_1990; 22nd October 2010 at 19:30.
GetLastError returns the last error message, it must be called immediately after the function that has failed, with no other function calls in-between. This is not the case for your code (you even have a qDebug between them), so it's useless in this case.
Put the call after the LoadLibrary, assign it to a variable, and either output it there, or put a breakpoint and check the value in the debugger.
Your call to GetLastError is too far away from the call site to be of any benefit (Qt is probably reseting it). You need to place the call immediately after a winapi call. In this case, it's a pain in the arse because that would require you to modify raw_mouse.cpp
Last edited by Timoteo; 22nd October 2010 at 19:35. Reason: hah! beaten!
Ok, I just saw I get some warnings:
Qt Code:
E:/QT Projects/rawInput-build-desktop/../rawInput/raw_mouse.c:154: warning: passing argument 1 of 'LoadLibraryW' from incompatible pointer type c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/winbase.h:1727: expected 'LPCWSTR' but argument is of type 'char *'To copy to clipboard, switch view to plain text mode
PS: Im trying to use GetLastError, but Im getting some problems fromQtCreator, so it will take a while.
That's probably why. You have unicode defined, but the source (raw_mouse.cpp) is using ANSI. I'm guessing that LoadLibrary has been failing all along with "no such file or directory". To continue as you are, you need to set your project up to use single-byte characters or you can patch raw_mouse.cpp to use the _TEXT() macro around the string literals. (e.g. _TEXT("user32.dll")).
Edit: After looking at it again, I can see that "char" is used too extensively to bother making it unicode compliant. Unless you have a compelling reason otherwise, you would be better served to just use ANSI encoding.
Last edited by Timoteo; 22nd October 2010 at 20:05.
How do I set the rest of my application to ANSI?
Edit:
GetLastError() outputs '5716627'.
5716627 doesn't sound like a valid error code, how do you get that?
Sorry to cut into the discussion but wouldn't it be simpler to rewrite this init_raw_mouse function to do the following instead of the "LoadLibrary" part?
Qt Code:
_RRID = RegisterRawInputDevices; if (!_RRID) return 2; _GRIDL = GetRawInputDeviceList; if (!_GRIDL) return 3; _GRIDIA = GetRawInputDeviceInfoA; if (!_GRIDIA) return 33; _GRID = GetRawInputData; if (!_GRID) return 4;To copy to clipboard, switch view to plain text mode
The rest of the code could stay the same.
been_1990 (22nd October 2010)
Yeah... Wise Wysota made it Work... Thanks! That solves the problem . Thanks to Timoteo and Squidge for helping.
Bookmarks