• Advertisement
Sign in to follow this  

direct x input problems

This topic is 2469 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'm learning direct x input from this book but I can't get my program to not crash. it builds ok but the DirectInput8Create always fails. I've searched on the internet and nothing helped. Here is my code:


HRESULT Result;

Result = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&KeyboardInput, NULL);
if(FAILED(Result))
{
MessageBox(NULL, "Error", "Failed to create keyboard input device!", MB_ICONERROR|MB_OK);
return -1;
}
Result = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&MouseInput, NULL);
if(FAILED(Result))
{
MessageBox(NULL, "Error", "Failed to create mouse input device!", MB_ICONERROR|MB_OK);
return -1;
}

KeyboardInput->CreateDevice(GUID_SysKeyboard, &KeyboardID, NULL);
MouseInput->CreateDevice(GUID_SysMouse, &MouseID, NULL);

KeyboardID->SetDataFormat(&c_dfDIKeyboard);
KeyboardID->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
KeyboardID->Acquire();


See anything wrong? I doubled check the code alot. it crashes on DirectInput8Create.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

1) DirectInput8Create() function creates an IDirectInput8* object. Why are you creating seperate objects for mouse and keyboard? It's irrelevant. Look:
LPDIRECTINPUT8 yourDirectInputObject = NULL;
Result = DirectInput8Create (hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*) &yourDirectInputObject, 0);
if (FAILED(Result))
//blah blah here.

LPDIRECTINPUTDEVICE8 pMouseDev = NULL, pKeyboardDev = NULL;
Result = yourDirectInputObject->CreateDevice (GUID_SysKeyboard, &pKeyboardDev, 0);
if (FAILED(Result))
//another blah blah here.

Result = yourDirectInputObject->CreateDevice (GUID_SysMouse, &pMouseDev, 0);
if (FAILED(Result))
//and another blah blah here.


For some details, take a look at here.

hth.
-R

Share this post


Link to post
Share on other sites
oh I get it. but it still dont get get why its failing. here the new code:


HRESULT Result;

Result = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&Input, NULL);
if(FAILED(Result))
{
MessageBox(NULL, "Failed to create input device!", "Error", MB_ICONERROR|MB_OK);
return -1;
}

Input->CreateDevice(GUID_SysKeyboard, &KeyboardID, NULL);
Input->CreateDevice(GUID_SysMouse, &MouseID, NULL);

KeyboardID->SetDataFormat(&c_dfDIKeyboard);
KeyboardID->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
KeyboardID->Acquire();

Share this post


Link to post
Share on other sites

oh I get it. but it still dont get get why its failing.

According to the documentation for DirectInput8Create, if the function fails, the return value can be one of four error codes. That should give you, and us, a better idea about what's going wrong.

Share this post


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

  • Advertisement