本文整理汇总了C++中LPDIRECTINPUT8::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUT8::QueryInterface方法的具体用法?C++ LPDIRECTINPUT8::QueryInterface怎么用?C++ LPDIRECTINPUT8::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUT8
的用法示例。
在下文中一共展示了LPDIRECTINPUT8::QueryInterface方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitDirectInput
HRESULT InitDirectInput(unsigned int joystick_index)
{
HRESULT hr;
state.is_initialized = false;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if (FAILED(hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, nullptr)))
return hr;
if (g_bFilterOutXinputDevices)
SetupForIsXInputDevice();
enumContext.pPreferredJoyCfg = &PreferredJoyCfg;
enumContext.bPreferredJoyCfgValid = false;
IDirectInputJoyConfig8* pJoyConfig = nullptr;
if (FAILED(hr = g_pDI->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig))) {
state.message = "QueryInterface on IID_IDirectInputJoyConfig8 failed";
return hr;
}
PreferredJoyCfg.dwSize = sizeof(PreferredJoyCfg);
if (SUCCEEDED(pJoyConfig->GetConfig(joystick_index, &PreferredJoyCfg, DIJC_GUIDINSTANCE))) { // This function is expected to fail if no joystick is attached
enumContext.bPreferredJoyCfgValid = true;
joystick_info.is_valid = true;
joystick_info.instance_guide = toDIGUID(PreferredJoyCfg.guidInstance);
joystick_info.pid_vid = toString(PreferredJoyCfg.wszType);
}
DIJT_SAFE_RELEASE(pJoyConfig);
// Look for a simple joystick we can use for this sample program.
if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
DirectInputJoyStick::impl::EnumJoysticksCallback,
this, DIEDFL_ATTACHEDONLY))) {
state.message = "EnumDevices failed";
return hr;
}
if (g_bFilterOutXinputDevices)
CleanupForIsXInputDevice();
// Make sure we got a joystick
if (!g_pJoystick)
{
state.message = "Joystick at index " + std::to_string(joystick_index) + " is not available";
return S_FALSE;
}
// Set the data format to "simple joystick" - a predefined data format
//
// A data format specifies which controls on a device we are interested in,
// and how they should be reported. This tells DInput that we will be
// passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2)))
{
state.message = "Device does not support DIJOYSTATE2";
return hr;
}
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
if (FAILED(hr = g_pJoystick->SetCooperativeLevel(NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) {
state.message = "SetCooperativeLevel failed";
return hr;
}
// Enumerate the joystick objects. The callback function enabled user
// interface elements for objects that are found, and sets the min/max
// values property for discovered axes.
if (FAILED(hr = g_pJoystick->EnumObjects(DirectInputJoyStick::impl::EnumObjectsCallback,
(VOID*) this, DIDFT_ALL))) {
state.message = "EnumObjects failed";
return hr;
}
InitForceFeedback();
state.is_initialized = true;
return S_OK;
}
示例2: open_dx_gamepad
C_RESULT open_dx_gamepad(void)
{
HRESULT hr;
HWND hDlg = GetConsoleHwnd();
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if (g_pDI==NULL)
if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return hr;
if( g_bFilterOutXinputDevices )
SetupForIsXInputDevice();
DIJOYCONFIG PreferredJoyCfg = {0};
DI_ENUM_CONTEXT enumContext;
enumContext.pPreferredJoyCfg = &PreferredJoyCfg;
enumContext.bPreferredJoyCfgValid = false;
IDirectInputJoyConfig8* pJoyConfig = NULL;
if( VP_FAILED( hr = g_pDI->QueryInterface( IID_IDirectInputJoyConfig8, ( void** )&pJoyConfig ) ) )
return hr;
PreferredJoyCfg.dwSize = sizeof( PreferredJoyCfg );
if( SUCCEEDED( pJoyConfig->GetConfig( 0, &PreferredJoyCfg, DIJC_GUIDINSTANCE ) ) ) // This function is expected to fail if no g_pJoystick is attached
enumContext.bPreferredJoyCfgValid = true;
SAFE_RELEASE( pJoyConfig );
// Look for a simple g_pJoystick we can use for this sample program.
if( VP_FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
Enumg_pJoysticksCallback,
&enumContext, DIEDFL_ATTACHEDONLY ) ) )
return hr;
if( g_bFilterOutXinputDevices )
CleanupForIsXInputDevice();
// Make sure we got a g_pJoystick
if( g_pJoystick == NULL )
{
//MessageBox( NULL, TEXT( "Joystick not found." ),
// TEXT( "A.R. Drone"),
// MB_ICONERROR | MB_OK );
// EndDialog( hDlg, 0 );
return C_FAIL;
}
// Set the data format to "simple g_pJoystick" - a predefined data format
//
// A data format specifies which controls on a device we are interested in,
// and how they should be reported. This tells DInput that we will be
// passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
if( VP_FAILED( hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) )
return C_FAIL;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
if( VP_FAILED( hr = g_pJoystick->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE |
DISCL_FOREGROUND ) ) )
return C_FAIL;
// Enumerate the g_pJoystick objects. The callback function enabled user
// interface elements for objects that are found, and sets the min/max
// values property for discovered axes.
if( VP_FAILED( hr = g_pJoystick->EnumObjects( EnumObjectsCallback,
( VOID* )hDlg, DIDFT_ALL ) ) )
return C_FAIL;
return C_OK;
}
示例3: QueryInterface
/*** IUnknown methods ***/
HRESULT _stdcall QueryInterface (REFIID riid, LPVOID * ppvObj)
{
return RealInput->QueryInterface(riid,ppvObj);
}