I am trying to set a second window pointer. I've tried to do it the two following ways.
SetWindowLong(m_hWnd,GWL_USERDATA+sizeof(long),(long) this);
SetWindowLong(m_hWnd,GWL_USERDATA+1,(long) this);
m_hWnd works, as does this. and right before I set it, I have created an instance of DirectInput8. How ever after I pass it I then use the following code
if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&m_pDI, NULL ) ) )
return Error("Failed to Initialize DirectInput");
SetWindowLong(m_hWnd,GWL_USERDATA+sizeof(long),(long) this);
hwnd=m_hWnd; //hwnd is global, m_hWnd is this instance of Input's local handle.
if( FAILED( hr = m_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
Joystickhandler,
NULL, DIEDFL_ATTACHEDONLY ) ) )
return false;
which works which leads to
BOOL CALLBACK Input::Joystickhandler( const DIDEVICEINSTANCE* pdidInstance,
VOID* pContext )
{
Input* entry = NULL ;
//entry = (Input *) GetWindowLong (hwnd, GWL_USERDATA+sizeof(long)) ;
return InitilaizeJoystick(pdidInstance);
}
Which is my code and then it crashes on
bool Input::InitilaizeJoystick(const DIDEVICEINSTANCE* pdidInstance){
HRESULT hr;
hr = m_pDI->CreateDevice( pdidInstance->guidInstance, &m_pJoystick, NULL );
if( FAILED(hr) )
return Error("On Create Joystic device");
I checked the debug and the pointer values are not pointing to the right stuff. I made sure when I said this I'm passing an Input, but I think setWindowLong is what is messing me up, I early had passed in a Long to a Graphics pointer.
What would the correct method to store a second link?
(if it matters I'm trying to get Direct input to enumerate my Joysticks)