Unable to Hook after Unhook

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
superema
Posts: 9
Joined: Sun Jan 03, 2010 2:44 pm

Unable to Hook after Unhook

Post by superema »

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;
}
superema
Posts: 9
Joined: Sun Jan 03, 2010 2:44 pm

Solved

Post by superema »

Actually the problem was a bit different:

the class had two member pointers
to the sensor and to the keyboard.

The first instance, even if it released the pointers, was not destroyed.
I destroyed it and now it works...
Post Reply