3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 #include <windows.h>
\r
27 #include "../ComObject.h"
\r
28 #include "../SlimDXException.h"
\r
29 #include "../InternalHelpers.h"
\r
30 #include "../CollectionShim.h"
\r
32 #include "DirectInput.h"
\r
33 #include "DirectInputException.h"
\r
34 #include "DirectInputNotFoundException.h"
\r
36 #include "CallbacksDI.h"
\r
37 #include "DeviceDI.h"
\r
39 using namespace System;
\r
40 using namespace System::Collections::Generic;
\r
41 using namespace System::Runtime::InteropServices;
\r
45 namespace DirectInput
\r
47 DirectInput::DirectInput()
\r
49 IDirectInput8W* dinput;
\r
50 IntPtr hInstance = Marshal::GetHINSTANCE( DirectInput::typeid->Module );
\r
54 HRESULT hr = DirectInput8Create( static_cast<HINSTANCE>( hInstance.ToPointer() ), DIRECTINPUT_VERSION,
\r
55 IID_IDirectInput8, reinterpret_cast<void**>( &dinput ), NULL );
\r
57 RECORD_DINPUT( hr );
\r
59 catch( SEHException^ ex )
\r
61 throw gcnew DirectInputNotFoundException( "DirectInput was not found. Reinstalling DirectX may fix the problem.", ex );
\r
64 if( dinput == NULL )
\r
65 throw gcnew DirectInputException( "Could not create DirectInput instance." );
\r
67 Construct( dinput );
\r
70 Result DirectInput::RunControlPanel()
\r
72 HRESULT hr = InternalPointer->RunControlPanel( NULL, 0 );
\r
73 return RECORD_DINPUT( hr );
\r
76 Result DirectInput::RunControlPanel( IntPtr parent )
\r
78 HRESULT hr = InternalPointer->RunControlPanel( static_cast<HWND>( parent.ToPointer() ), 0 );
\r
79 return RECORD_DINPUT( hr );
\r
82 bool DirectInput::IsDeviceAttached( Guid device )
\r
84 HRESULT hr = InternalPointer->GetDeviceStatus( Utilities::ConvertManagedGuid( device ) );
\r
85 RECORD_DINPUT( hr );
\r
90 Guid DirectInput::FindDevice( Guid deviceClass, String^ name )
\r
93 pin_ptr<const wchar_t> pinnedName = PtrToStringChars( name );
\r
95 HRESULT hr = InternalPointer->FindDevice( Utilities::ConvertManagedGuid( deviceClass ),
\r
96 reinterpret_cast<LPCTSTR>( pinnedName ), &result );
\r
97 RECORD_DINPUT( hr );
\r
100 return Guid::Empty;
\r
102 return Utilities::ConvertNativeGuid( result );
\r
105 IList<DeviceInstance^>^ DirectInput::GetDevices()
\r
107 return GetDevices( DeviceClass::All, DeviceEnumerationFlags::AllDevices );
\r
110 IList<DeviceInstance^>^ DirectInput::GetDevices( DeviceClass deviceClass, DeviceEnumerationFlags enumerationFlags )
\r
112 List<DeviceInstance^>^ results = gcnew List<DeviceInstance^>();
\r
113 CollectionShim<DeviceInstance^> shim( results );
\r
115 HRESULT hr = InternalPointer->EnumDevices( static_cast<DWORD>( deviceClass ), static_cast<LPDIENUMDEVICESCALLBACK>( EnumerateDevices ), &shim, static_cast<DWORD>( enumerationFlags ) );
\r
116 if( RECORD_DINPUT( hr ).IsFailure )
\r
122 IList<DeviceInstance^>^ DirectInput::GetDevices( DeviceType deviceType, DeviceEnumerationFlags enumerationFlags )
\r
124 List<DeviceInstance^>^ results = gcnew List<DeviceInstance^>();
\r
125 CollectionShim<DeviceInstance^> shim( results );
\r
127 HRESULT hr = InternalPointer->EnumDevices( static_cast<DWORD>( deviceType ), static_cast<LPDIENUMDEVICESCALLBACK>( EnumerateDevices ), &shim, static_cast<DWORD>( enumerationFlags ) );
\r
128 if( RECORD_DINPUT( hr ).IsFailure )
\r