CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007
    Location
    Vercelli, Italy
    Posts
    87

    [RESOLVED] RegisterRawInputDevices fails with no error

    Hi everyone,

    I want to use the RawInput API in my program to handle HIDs. However, I can't even register any device, as RegisterRawInputDevices fails (returns FALSE). When I call GetLastError(), I get 0, which means no error.

    Here's my code, which is a minimal variation of the example taken from the MSDN:
    Code:
    #include <windows.h>
    
    int main(int argc, char** argv)
    {
    	RAWINPUTDEVICE Rid[2];
    	    
    	Rid[0].usUsagePage = 0x01; 
    	Rid[0].usUsage = 0x02; 
    	Rid[0].dwFlags = RIDEV_NOLEGACY;   // adds HID mouse and also ignores legacy mouse messages
    	Rid[0].hwndTarget = 0;
    
    	Rid[1].usUsagePage = 0x01; 
    	Rid[1].usUsage = 0x06; 
    	Rid[1].dwFlags = RIDEV_NOLEGACY;   // adds HID keyboard and also ignores legacy keyboard messages
    	Rid[1].hwndTarget = 0;
    
    	if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) 
    	{
    		DWORD err = GetLastError();
    	}
    
    	return 0;
    }
    I've tried similar code (I don't have it here, so I can't make an accurate line-to-line comparison) on another machine, and there it worked. On my laptop, it worked for a while, then it stopped working.

    I suspect this has something to do with my specific setup; in particular, in (apparently) unrelated news, I installed and configured (and re-configured) software such as PPJoy in order to use a Wiimote as a HID. However, my software didn't work before installing PPJoy, started working after some tentative configurations of PPJoy, then stopped working again.

    I will perform tests on other machines, to check if my experiments broke something, but before that I would like to know if some of you have had a similar experience. I find it especially weird that RegisterRawInputDevices fails without marking any error...
    Last edited by Sk#; June 8th, 2010 at 05:03 PM.

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: RegisterRawInputDevices fails with no error

    Could it be a permission issue? It works for me (running as administrator in Win7).

  3. #3
    Join Date
    Jun 2007
    Location
    Vercelli, Italy
    Posts
    87

    Re: RegisterRawInputDevices fails with no error

    hoxsiew: it was in fact a problem of permission... of sort.

    As I said I'd do, I tried the same program on my other computer. This one had an almost fresh install of Windows, and I installed VC++ 2008 this very night... and still the program failed to register the devices. But as soon as I stepped through the RegisterRawInputDevices call... the popup of Comodo's Sandbox came out!

    So, for everyone who happens to have a similar problem: Comodo thinks that trying to access the keyboard directly is a symptom of a program trying to harm your PC. Which may in fact be, to be honest. So, if you have Comodo, chances are that it will automatically block your RawInput code. This will result in the call to RegisterRawInputDevices to fail, in no error being logged, and all other RawInput functions (listing the devices, getting info about them...) working correctly.

    The quick and dirty solution is to set the "Sandbox Security Level" to "Disabled". I'll investigate further and see what exactly needs to be done to provide better security.

    I am now worried, though, that users running Comodo won't be able to use my program. THey'll launch the executable, Comodo will block the registration of raw input devices, and it may or may not tell them about it. This will result in raw input not being available. What should I do in such a case? Should I fall back to legacy input? Should the user be warned about this somehow?

    [EDIT] The call works fine if the executable is added to the Sandbox list and set as "Unlimited" (may work also with a slightly less permissive setting, I haven't tried). Go to Defense+, Sandbox, and Add a Program to the Sandbox. Care must be taken if your executable is on a virtual disk (mapped on a folder with subst): in that case, the original path (for example, C:\VirtualDisk\...) must be specified, and not the mapped one (D:\...).
    Last edited by Sk#; June 8th, 2010 at 05:01 PM. Reason: More info about Comodo configuration

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured