Hello
I wrote a class that is an event_receiver of a 3D Mouse.
It can Connect, hook to events and Disconnect.
The first time I istance and connect one of them, it handles key events correctly. Then, after disconnecting, deleting and creating a new instance and reconnecting, it is does not receive events anymore.
Every method returns OK, what could be???
Thanks in advance,
E.
PS: these are the connect and disconnect methods
bool TD3DxMouse::Initialize(void)
{
HRESULT hr;
CComPtr<IUnknown> _3DxDevice;
// Create the device object
hr = _3DxDevice.CoCreateInstance( __uuidof( Device ) );
if ( SUCCEEDED( hr ) )
{
CComPtr<ISimpleDevice> _3DxSimpleDevice;
hr = _3DxDevice.QueryInterface( &_3DxSimpleDevice );
if ( SUCCEEDED( hr ) )
{
hr = HookEvents( _3DxSimpleDevice );
if ( SUCCEEDED( hr ) )
{
// Connect to the driver
_3DxSimpleDevice->Connect();
// Query type: if returns 0 it means "driver is down"
_3DxSimpleDevice->get_Type( &m_lType );
}
}
_3DxDevice.Release();
}
return SUCCEEDED(hr);
}
void TD3DxMouse::Terminate(void)
{
HRESULT hr = E_FAIL;
CComPtr<IDispatch> _3DxDevice;
if (m_pISensor)
hr = m_pISensor->get_Device(&_3DxDevice);
else if (m_pIKeyboard)
hr = m_pIKeyboard->get_Device(&_3DxDevice);
if (SUCCEEDED(hr))
{
CComPtr<ISimpleDevice> _3DxSimpleDevice;
hr = _3DxDevice.QueryInterface(&_3DxSimpleDevice);
if (SUCCEEDED(hr))
_3DxSimpleDevice->Disconnect();
}
if (m_pISensor)
{
// unhook (unadvise) the sensor event sink
__unhook( &_ISensorEvents::SensorInput, m_pISensor,
&TD3DxMouse::OnSensorInput );
m_pISensor.Release();
}
if (m_pIKeyboard)
{
__unhook( &_IKeyboardEvents::KeyDown, m_pIKeyboard,
&TD3DxMouse::OnKeyDown );
m_pIKeyboard.Release();
}
m_pISensor = 0;
m_pIKeyboard = 0;
}
Unable to Hook after Unhook
Moderator: Moderators