ULONG _stdcall Release(void) {
		if(--Refs==0) {
			RealDevice->Release();
			delete this;
			return 0;
		} else { return Refs; }
	}
Exemplo n.º 2
0
    // Callback that lists all gamepads.
    static BOOL CALLBACK gamepadCallback(LPCDIDEVICEINSTANCE device,
        LPVOID userData)
    {
        Impl* pimpl = static_cast<Impl*>(userData);

        IDirectInputDevice8* gamepad;
        if (FAILED(pimpl->input->CreateDevice(device->guidInstance,
            &gamepad, 0)))
        {
            return DIENUM_CONTINUE;
        }

        if (FAILED(gamepad->SetDataFormat(&c_dfDIJoystick)) ||
            FAILED(gamepad->SetCooperativeLevel(pimpl->window,
                DISCL_EXCLUSIVE | DISCL_FOREGROUND)) ||
            FAILED(gamepad->EnumObjects(axisCallback, gamepad, DIDFT_AXIS)))
        {
            gamepad->Release();
            return DIENUM_CONTINUE;
        }

        pimpl->gamepads.push_back(Win::shareComPtr(gamepad));

        return DIENUM_CONTINUE;
    }
Exemplo n.º 3
0
IDirectInputDevice8 *BaseInputDevice::create_device(IDirectInput8 *pDI, GUID guid)
{
    IDirectInputDevice8 *device;
    HRESULT hr;
    
    hr = pDI->CreateDevice(guid, &device, NULL);
    if(FAILED(hr))  return NULL;
    
    hr = device->SetCooperativeLevel(Render::hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    if(FAILED(hr))
    {
        device->Release();  return NULL;
    }
    
    device->Acquire();
    return device;
}