Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to I pass a variable over to this?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 19 July 2012 - 09:52 PM

Hi guys,

I am making a simple joystick wrapper (class) for my application. All has gone well except I cant figure out out to get this final varibale in place. The variable in question is mDInput (6th line of code).

BOOL CALLBACK Input::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance,VOID* pContext)
{
// Get access to class variables
IDirectInputDevice8  *p_context=(IDirectInputDevice8*)pContext;
DIDEVICEINSTANCE  *p_pdidInstance=(DIDEVICEINSTANCE*)pdidInstance;
// Obtain an interface to the enumerated joystick.
HRESULT hr=mDInput->CreateDevice(p_pdidInstance->guidInstance,&p_context,NULL);
// If it failed, then we can't use this joystick. (Maybe the user unplugged it while we were in the middle of enumerating it.)
if(FAILED(hr))
  return DIENUM_CONTINUE;
// Stop enumeration. Note: we're just taking the first joystick we get. You could store all the enumerated joysticks and let the user pick.
return DIENUM_STOP;
}

This is a static call back within the 'Input' class & mDInput is located in the private: section (IDirectInput8 *mDInput;)

Any help would be awesome. I prefer not to make mDInput global.

Thanks in advance :)

Sponsor:

#2 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 19 July 2012 - 10:18 PM

I have just tried making mDinput static and changing the Callback to this. But, now I get linker errors :(

BOOL CALLBACK Input::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance,VOID* pContext)
{
IDirectInputDevice8  *p_context=(IDirectInputDevice8*)pContext;
DIDEVICEINSTANCE  *p_pdidInstance=(DIDEVICEINSTANCE*)pdidInstance;
IDirectInput8 *p_mDInput=(Input::GetIDirectInput8());
HRESULT hr=p_mDInput->CreateDevice(p_pdidInstance->guidInstance,&p_context,NULL);
if(FAILED(hr))
  return DIENUM_CONTINUE;
return DIENUM_STOP;
}


#3 Codarki   Members   -  Reputation: 462

Like
1Likes
Like

Posted 20 July 2012 - 03:38 AM

The documentation says that 2nd parameter, the void pointer, is application defined value passed to the enum callback.

Try passing a pointer to a struct when you call the enum function, something like:

struct JoysticEnumParams
{
IDirectInputDevice8* context;
IDirectInput8 *DInput;
};


#4 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 20 July 2012 - 03:55 AM

Awesome, I got so tunnel-visioned with this that I missed that you had to pass the wanted void pointer from the caller.

Turns out when I checked, I was passing NULL.

Thank you so much Codarki. :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS