本文整理汇总了C++中LPDIRECTINPUTDEVICE8::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE8::QueryInterface方法的具体用法?C++ LPDIRECTINPUTDEVICE8::QueryInterface怎么用?C++ LPDIRECTINPUTDEVICE8::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE8
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE8::QueryInterface方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Open
bool DIDevice::Open()
{
m_sName = ConvertACPToUTF8( JoystickInst.tszProductName );
LOG->Trace( "Opening device '%s'", m_sName.c_str() );
buffered = true;
LPDIRECTINPUTDEVICE8 tmpdevice;
// load joystick
HRESULT hr = g_dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, nullptr );
if ( hr != DI_OK )
{
LOG->Info( hr_format(hr, "OpenDevice: IDirectInput_CreateDevice") );
return false;
}
hr = tmpdevice->QueryInterface( IID_IDirectInputDevice8, (LPVOID *) &Device );
tmpdevice->Release();
if ( hr != DI_OK )
{
LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice::QueryInterface", m_sName.c_str()) );
return false;
}
int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
if( type == KEYBOARD )
coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
hr = Device->SetCooperativeLevel( GraphicsWindow::GetHwnd(), coop );
if ( hr != DI_OK )
{
LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetCooperativeLevel", m_sName.c_str()) );
return false;
}
switch(type)
{
case KEYBOARD:
hr = Device->SetDataFormat( &c_dfDIKeyboard );
break;
case JOYSTICK:
hr = Device->SetDataFormat( &c_dfDIJoystick );
break;
case MOUSE:
hr = Device->SetDataFormat( &c_dfDIMouse );
break;
}
if ( hr != DI_OK )
{
LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetDataFormat", m_sName.c_str()) );
return false;
}
switch( type )
{
case JOYSTICK:
Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
break;
case KEYBOARD:
// Always 256-button.
for( int b = 0; b < 256; ++b )
{
input_t in;
in.type = in.KEY;
in.num = ConvertScancodeToKey(b);
in.ofs = b;
buttons++;
Inputs.push_back(in);
}
break;
case MOUSE:
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_ANYINSTANCE );
break;
}
{
DIPROPDWORD dipdw;
memset(&dipdw, 0, sizeof(dipdw));
dipdw.diph.dwSize = sizeof(dipdw);
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = INPUT_QSIZE;
hr = Device->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
if ( hr == DI_POLLEDDEVICE )
{
/* This device doesn't support buffering, so we're forced
* to use less reliable polling. */
buffered = false;
}
else if ( hr != DI_OK )
{
LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetProperty", m_sName.c_str()) );
return false;
}
}
return true;
}
示例2: QueryInterface
/*** IUnknown methods ***/
HRESULT _stdcall QueryInterface (REFIID riid, LPVOID * ppvObj) {
return RealDevice->QueryInterface(riid,ppvObj);
}