unsafe bool InitInternal(IntPtr windowHandle, IDirectInput *alreadyCreatedDirectInput) { int hr; if (alreadyCreatedDirectInput == null) { void */*IDirectInput*/ directInputTemp; GUID iidDIrectInput = DInput.IID_IDirectInput8W; hr = DInput.DirectInput8Create(ref iidDIrectInput, out directInputTemp); if (DirectInput.Wrapper.FAILED(hr)) { Log.Info("SystemMouseDevice: DirectInput: DirectInput8Create failed."); return(false); } directInput = (IDirectInput *)directInputTemp; needReleaseDirectInput = true; } else { directInput = alreadyCreatedDirectInput; } void */*IDirectInputDevice8*/ mouseDeviceTemp; GUID guidSysMouse = DInput.GUID_SysMouse; hr = IDirectInput.CreateDevice(directInput, ref guidSysMouse, out mouseDeviceTemp, null); if (Wrapper.FAILED(hr)) { Log.Info("SystemMouseDevice: DirectInput: CreateDevice failed."); return(false); } mouseDevice = (IDirectInputDevice8 *)mouseDeviceTemp; hr = IDirectInputDevice8.SetDataFormat(mouseDevice, DInput.Get_c_dfDIMouse()); if (Wrapper.FAILED(hr)) { Log.Info("SystemMouseDevice: DirectInput: SetDataFormat failed."); return(false); } //!!!!для Game.exe включать //if( windowHandle != IntPtr.Zero ) // Acquire( windowHandle ); return(true); }
internal unsafe bool Init() { GUID devGuid = deviceGuid; void */*IDirectInputDevice8*/ directInputDeviceTemp = null; int hr = IDirectInput.CreateDevice( WindowsInputDeviceManager.Instance.DirectInput, ref devGuid, out directInputDeviceTemp, null); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot create device \"{0}\" ({1}).", Name, DInput.GetOutString(DInput.DXGetErrorStringW(hr))); return(false); } directInputDevice = (IDirectInputDevice8 *)directInputDeviceTemp; // get capabilities DIDEVCAPS caps = new DIDEVCAPS(); caps.dwSize = (uint)sizeof(DIDEVCAPS); hr = IDirectInputDevice8.GetCapabilities(directInputDevice, ref caps); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot get device capabilities \"{0}\".", Name); return(false); } //buttons Button[] buttons = new Button[caps.dwButtons]; for (int n = 0; n < buttons.Length; n++) { buttons[n] = new Button((JoystickButtons)n, n); } //povs POV[] povs = new POV[caps.dwPOVs]; for (int n = 0; n < povs.Length; n++) { povs[n] = new JoystickInputDevice.POV((JoystickPOVs)n); } // setup hr = IDirectInputDevice8.SetDataFormat(directInputDevice, DInput.Get_c_dfDIJoystick2()); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot set device data format \"{0}\".", Name); return(false); } hr = IDirectInputDevice8.SetCooperativeLevel(directInputDevice, WindowsInputDeviceManager.Instance.WindowHandle, DInput.DISCL_EXCLUSIVE | DInput.DISCL_FOREGROUND); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot set device " + "cooperative level \"{0}\".", Name); return(false); } //------------------------------------------------------------------- // setup size for buffered input DIPROPDWORD dibuf = new DIPROPDWORD(); dibuf.diph.dwSize = (uint)sizeof(DIPROPDWORD); dibuf.diph.dwHeaderSize = (uint)sizeof(DIPROPHEADER); dibuf.diph.dwHow = DInput.DIPH_DEVICE; dibuf.diph.dwObj = 0; dibuf.dwData = BufferSize; GUID *bufferSizeGuid = (GUID *)DInput.getDIPROP_BUFFERSIZE(); hr = IDirectInputDevice8.SetProperty(directInputDevice, bufferSizeGuid, ref dibuf.diph); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot set device buffer size \"{0}\".", Name); return(false); } deviceDataBuffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, sizeof(DIDEVICEOBJECTDATA) * BufferSize); //-------------------------------------------------------------------- temporarySliderCount = 0; temporaryAxisList = new List <JoystickInputDevice.Axis>(); tempDeviceForEnumerate = this; hr = IDirectInputDevice8.EnumObjects(directInputDevice, EnumDeviceObjectsHandler, null, DInput.DIDFT_ALL); tempDeviceForEnumerate = null; if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickDevice: Cannot enumerate device objects \"{0}\".", Name); return(false); } //axes Axis[] axes = temporaryAxisList.ToArray(); temporaryAxisList = null; //sliders Slider[] sliders = new Slider[temporarySliderCount]; for (int n = 0; n < sliders.Length; n++) { sliders[n] = new JoystickInputDevice.Slider((JoystickSliders)n); } //forceFeedbackController ForceFeedbackController forceFeedbackController = null; if ((caps.dwFlags & DInput.DIDC_FORCEFEEDBACK) != 0) { forceFeedbackController = new DirectInputForceFeedbackController(directInputDevice, this); } //initialize data InitDeviceData(buttons, axes, povs, sliders, forceFeedbackController); return(true); }