• Advertisement
Sign in to follow this  

How to I pass a variable over to this?

This topic is 2013 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

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 :)

Share this post


Link to post
Share on other sites
Advertisement
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;
}

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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. :)

Share this post


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

  • Advertisement