unsafe bool CreateDevices() { // check for XInput presense haveXInput = XInput.IsXInputPresent(); if (haveXInput) { XINPUT_STATE state = new XINPUT_STATE(); for (int n = 0; n < XInput.MaxControllers; n++) { int result = XInput.GetState(n, ref state); if (!XInputNativeWrapper.Wrapper.FAILED(result)) { string name = string.Format("XBox Controller {0}", n); WindowsXBoxGamepad device = new WindowsXBoxGamepad(name, n); if (!device.Init()) { device.CallOnShutdown(); continue; } RegisterDevice(device); } } } // check for DirectInput devices int hr = IDirectInput.EnumDevices(directInput, DInput.DI8DEVCLASS_GAMECTRL, EnumDevicesHandler, null, DInput.DIEDFL_ATTACHEDONLY); if (global::DirectInput.Wrapper.FAILED(hr)) { Log.Warning("WindowsInputDeviceManager: IDirectInput.EnumDevices failed ({0}).", DInput.GetOutString(DInput.DXGetErrorStringW(hr))); return(false); } return(true); }