Jump to content
  • Advertisement
Sign in to follow this  

Using Setwindowlong more then once.

This topic is 5005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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, 
                                         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){
	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)

Share this post

Link to post
Share on other sites
You should check the docs for GetWindowLong. GWL_USERDATA is not to be used as a base offset to access extra window memory. For that, you need to specify cbWndExtra when using RegisterClassEx, and then call Get/SetWindowLong with the offset you want (starting at 0). However, if you're not registering your own class, just use GWL_USERDATA to store a pointer to a structure that contains all the data you need.

Share this post

Link to post
Share on other sites
C++ You confounded me again!! *shakes fist*

yeah I was placing the GWL_USERDATA there when I shouldn't. I figured it was a Define or something.

and thanks for meantioning cbWndExtra I didn't know it's use I must hav eskimmed over that part when reading about the functions. Every time I feel that I am very clever, I prove I'm not :)

Share this post

Link to post
Share on other sites
I'd like to mention a method i've seen documented but actually noone uses:

SetProp lets you assign values to a HWND based on a string. It looks like there's no limit on them, only downside, you have to remove them before the HWND gets destroyed.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!