Thread: Working with joystick/gamepad from service

  1. #1
    Registered User
    Join Date
    Aug 2005

    Working with joystick/gamepad from service

    I am trying to use a gamepad/joystick to control some hardware.

    Industrial compurer (WinXP) runs all software as services so no login is required. The computer itself is hidden from an operator, actually.

    I need exclusive access to the game controller to catch operators actions (buttons) and feed back system's status as force feedback effects.

    The problem is that DirectInput requires HWND descriptor to work with gamepads (SetCooperativeLevel function). I obviously do not have a window for that.

    Does anybody know how to work with USB-based HID from a service?


  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Welcome to the forums!

    Why can't you create a window. I think you will be able to create a window and use DirectInput or the joystick API (no guarantees!).

    When you have a window, you need a message loop. You will also need to attach your thread to the interactive/input desktop. The code to do that should look something like this:
        HWINSTA  hwinstaSave; 
        HDESK    hdeskSave; 
        HWINSTA  hwinstaUser; 
        HDESK    hdeskUser; 
        // Ensure connection to service window station and desktop, and save their handles. 
        hwinstaSave = GetProcessWindowStation(); 
        hdeskSave = GetThreadDesktop(dwThreadId); 
        // Connect to the interactive window station and desktop. 
        hwinstaUser = OpenWindowStation(TEXT("WinSta0"), FALSE, MAXIMUM_ALLOWED); 
        hdeskUser = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED); 
        // Create window, receive input, etc here!
        // Once you're done restore window station and desktop. 
    However, I'm not sure whether you can attach to the WinLogon desktop, so you'll have to try it and see.

  3. #3
    Registered User
    Join Date
    Aug 2005


    I will try this approach.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-03-2005, 01:03 AM
  2. Running External Process from service
    By rotis23 in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2004, 08:56 AM
  3. writing a windows service
    By talz13 in forum Windows Programming
    Replies: 2
    Last Post: 07-01-2004, 06:32 AM
  4. Win32 Service for FileChangeNotification
    By caefer in forum Windows Programming
    Replies: 6
    Last Post: 01-06-2004, 10:56 PM
  5. windows service + hooks + dll
    By rotis23 in forum Windows Programming
    Replies: 5
    Last Post: 09-04-2003, 07:06 AM