当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTINPUTDEVICE::QueryInterface方法代码示例

本文整理汇总了C++中LPDIRECTINPUTDEVICE::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE::QueryInterface方法的具体用法?C++ LPDIRECTINPUTDEVICE::QueryInterface怎么用?C++ LPDIRECTINPUTDEVICE::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECTINPUTDEVICE的用法示例。


在下文中一共展示了LPDIRECTINPUTDEVICE::QueryInterface方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EnumJoystickProc

BOOL CALLBACK EnumJoystickProc (LPCDIDEVICEINSTANCE pdiDevice_, LPVOID lpv_)
{
    HRESULT hr;

    LPDIRECTINPUTDEVICE pdiJoystick;
    if (FAILED(hr = pdi->CreateDevice(pdiDevice_->guidInstance, &pdiJoystick, NULL)))
        TRACE("!!! Failed to create joystick device (%#08lx)\n", hr);
    else
    {
        DIDEVICEINSTANCE didi = { sizeof(didi) };
        strcpy(didi.tszInstanceName, "<unknown>");  // WINE fix for missing implementation

        if (FAILED(hr = pdiJoystick->GetDeviceInfo(&didi)))
            TRACE("!!! Failed to get joystick device info (%#08lx)\n", hr);

        // Overloaded use - if custom data was supplied, it's a combo box ID to add the string to
        else if (lpv_)
            SendMessage(reinterpret_cast<HWND>(lpv_), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(didi.tszInstanceName));
        else
        {
            IDirectInputDevice2* pDevice;

            // We need an IDirectInputDevice2 interface for polling, so query for it
            if (FAILED(hr = pdiJoystick->QueryInterface(IID_IDirectInputDevice2, reinterpret_cast<void **>(&pDevice))))
                TRACE("!!! Failed to query joystick for IID_IDirectInputDevice2 (%#08lx)\n", hr);

            // If the device name matches the joystick 1 device name, save a pointer to it
            else if (!lstrcmpi(didi.tszInstanceName, GetOption(joydev1)))
                pdidJoystick1 = pDevice;

            // If the device name matches the joystick 2 device name, save a pointer to it
            else if (!lstrcmpi(didi.tszInstanceName, GetOption(joydev2)))
                pdidJoystick2 = pDevice;

            // No match
            else
                pDevice->Release();

            pdiJoystick->Release();
        }
    }

    // Continue looking for other devices, even tho we failed with the current one
    return DIENUM_CONTINUE;
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:45,代码来源:Input.cpp

示例2: EnumJoysticksCallback

//-----------------------------------------------------------------------------
// Function: EnumJoysticksCallback
//
// Description: 
//      Called once for each enumerated joystick. If we find one, 
//       create a device interface on it so we can play with it.
//
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumJoysticksCallback( LPCDIDEVICEINSTANCE pInst, 
                                     LPVOID lpvContext )
{
    HRESULT             hr;
    LPDIRECTINPUTDEVICE pDevice;

    // obtain an interface to the enumerated force feedback joystick.
    hr = lpdi->CreateDevice( pInst->guidInstance, &pDevice, NULL );

    // if it failed, then we can't use this joystick for some
    // bizarre reason.  (Maybe the user unplugged it while we
    // were in the middle of enumerating it.)  So continue enumerating
    if ( FAILED(hr) ) 
        return DIENUM_CONTINUE;

    // we successfully created an IDirectInputDevice.  So stop looking 
    // for another one.
    g_pJoystick = pDevice;

    // query for IDirectInputDevice2 - we need this to poll the joystick 
    pDevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *)&g_pJoystickDevice2 );

    return DIENUM_STOP;
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:32,代码来源:Di_func.cpp

示例3: PisteInput_Alusta_Ohjain

bool PisteInput_Alusta_Ohjain(int index)
{
	LPDIRECTINPUTDEVICE temp;
	
	if (FAILED(PI_lpdi->CreateDevice(PI_joysticks[index].joystickGUID, &temp, NULL))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Create device failed! \n");
		return false;
	}

	if (FAILED(temp->QueryInterface(IID_IDirectInputDevice2,(void**) &PI_joysticks[index].lpdijoy))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Create device failed! \n");
		return false;
	}

	if (FAILED(temp->Release())) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Releasing DirectInputDevice 1 failed! \n");
		return false;
	}

	if (FAILED(PI_joysticks[index].lpdijoy->SetCooperativeLevel(PI_main_window_handle, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE	))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Releasing DirectInputDevice 1 failed! \n");
		return false;
	}

	if (FAILED(PI_joysticks[index].lpdijoy->SetDataFormat(&c_dfDIJoystick))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Set dataformat failed! \n");
		return false;
	}

	DIPROPRANGE joy_axis_range;

	//Määritellään x-akseli
	
	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_X;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	//Määritellään y-akseli

	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_Y;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	DIPROPDWORD dead_angle;

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_X;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_Y;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	if (FAILED(PI_joysticks[index].lpdijoy->Acquire())) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Acquiring device failed! \n");
		return false;
	}

	return true;
}
开发者ID:stt,项目名称:pk2,代码行数:74,代码来源:PisteInput.cpp

示例4: DIUtilCreateDevice2FromJoyConfig

//===========================================================================
// DIUtilCreateDevice2FromJoyConfig
//
// Helper function to create a DirectInputDevice2 object from a 
//  DirectInputJoyConfig object.
//
// Parameters:
//  short                   nJoystickId     - joystick id for creation
//  HWND                    hWnd            - window handle
//  LPDIRECTINPUT           pdi             - ptr to base DInput object
//  LPDIRECTINPUTJOYCONFIG  pdiJoyCfg       - ptr to joyconfig object
//  LPDIRECTINPUTDEVICE     *ppdiDevice2    - ptr to device object ptr
//
// Returns: HRESULT
//
//===========================================================================
HRESULT DIUtilCreateDevice2FromJoyConfig(short nJoystickId, HWND hWnd,
                            LPDIRECTINPUT pdi,
                            LPDIRECTINPUTJOYCONFIG pdiJoyCfg,
                            LPDIRECTINPUTDEVICE2 *ppdiDevice2)
{
    HRESULT                 hRes        = E_NOTIMPL;
    LPDIRECTINPUTDEVICE     pdiDevTemp  = NULL;
    DIJOYCONFIG             dijc;
    
    // validate pointers
    if( (IsBadReadPtr((void*)pdi, sizeof(IDirectInput))) ||
        (IsBadWritePtr((void*)pdi, sizeof(IDirectInput))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid pdi\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) ||
        (IsBadWritePtr((void*)pdiJoyCfg, sizeof(IDirectInputJoyConfig))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid pdiJoyCfg\n"));
        return E_POINTER;
    }
    if( (IsBadReadPtr((void*)ppdiDevice2, sizeof(LPDIRECTINPUTDEVICE2))) ||
        (IsBadWritePtr((void*)ppdiDevice2, sizeof(LPDIRECTINPUTDEVICE2))) )
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - invalid ppdiDevice2\n"));
        return E_POINTER;
    }

    // get the instance GUID for device configured as nJoystickId
    // 
    // GetConfig will provide this information
    dijc.dwSize = sizeof(DIJOYCONFIG);
    hRes = pdiJoyCfg->GetConfig(nJoystickId, &dijc, DIJC_GUIDINSTANCE);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - GetConfig() failed\n"));
        return hRes;
    }

    // create temporary device object
    //
    // use the instance GUID returned by GetConfig()
    hRes = pdi->CreateDevice(dijc.guidInstance, &pdiDevTemp, NULL);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - CreateDevice() failed\n"));
        return hRes;
    }

    // query for a device2 object
    hRes = pdiDevTemp->QueryInterface(IID_IDirectInputDevice2, (LPVOID*)ppdiDevice2);
    
    // release the temporary object
    pdiDevTemp->Release();

    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - QueryInterface(IDirectInputDevice2) failed\n"));
        return hRes;
    }

    // set the desired data format
    //
    // we want to be a joystick
    hRes = (*ppdiDevice2)->SetDataFormat(&c_dfDIJoystick);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - SetDataFormat(Joystick) failed\n"));
        return hRes;
    }
    
    // set the cooperative level for the device
    //
    // want to set EXCLUSIVE | BACKGROUND
    hRes = (*ppdiDevice2)->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
    if(FAILED(hRes))
    {
        ERROUT(TEXT("DIUtilCreateDeviceFromJoyConfig() - SetCooperativeLevel() failed\n"));
        return hRes;
    }

    // all is well
    return hRes;
//.........这里部分代码省略.........
开发者ID:arielscarpinelli,项目名称:ntpad,代码行数:101,代码来源:Dicputil.cpp

示例5:

/**
 * input_dinput_callback_init_joysticks_enum(): EnumDevices callback for initializing joysticks.
 * @param lpDIIJoy Joystick information.
 * @param pvRef hWnd of the Gens window.
 * @return DIENUM_CONTINUE to continue the enumeration; DIENUM_STOP to stop the enumeration.
 */
static BOOL CALLBACK input_dinput_callback_init_joysticks_enum(LPCDIDEVICEINSTANCE lpDIIJoy, LPVOID pvRef)
{
	HRESULT rval;
	LPDIRECTINPUTDEVICE lpDIJoy;
 
	if (!lpDIIJoy || input_dinput_num_joysticks >= MAX_JOYS ||
	    input_dinput_callback_init_joysticks_enum_counter >= MAX_JOYS)
		return DIENUM_STOP;
	
	// Number of times this function has been called.
	int cur_joystick = input_dinput_callback_init_joysticks_enum_counter;
	input_dinput_callback_init_joysticks_enum_counter++;
	
	rval = lpDI->CreateDevice(lpDIIJoy->guidInstance, &lpDIJoy, NULL);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDI->CreateDevice() failed. (Joystick %d)", cur_joystick);
		return DIENUM_CONTINUE;
	}
	
	IDirectInputDevice2 *pJoyDevice = NULL;
	input_dinput_joy_id[input_dinput_num_joysticks] = NULL;
	rval = lpDIJoy->QueryInterface(IID_IDirectInputDevice2, (void**)&pJoyDevice);
	
	lpDIJoy->Release();
	if (rval != DI_OK || !pJoyDevice)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDIJoy->QueryInterface() failed. (Joystick %d)", cur_joystick);
		return DIENUM_CONTINUE;
	}
	
	rval = pJoyDevice->SetDataFormat(&c_dfDIJoystick);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"pJoyDevice->SetDatFormat(&c_dfDIJoystick) failed. (Joystick %d)", cur_joystick);
		pJoyDevice->Release();
		return DIENUM_CONTINUE;
	}
	
	// TODO: Add an option to specify DISCL_FOREGROUND so the joysticks only work when the Gens window is active.
	rval = pJoyDevice->SetCooperativeLevel((HWND)pvRef, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
	
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_WARNING,
			"pJoyDevice->SetCooperativeLevel() failed. (Joystick %d)", cur_joystick);
		pJoyDevice->Release();
		return DIENUM_CONTINUE;
	}
	
	// Attempt to acquire the joystick device.
	for (unsigned int i = 10; i != 0; i--)
	{
		rval = pJoyDevice->Acquire();
		if (rval == DI_OK)
			break;
		GensUI::sleep(10);
	}
	
	input_dinput_joy_id[input_dinput_num_joysticks] = pJoyDevice;
	input_dinput_num_joysticks++;
	
	return DIENUM_CONTINUE;
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:73,代码来源:input_dinput.cpp


注:本文中的LPDIRECTINPUTDEVICE::QueryInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。