Skip to main content
gamedev.net
🔒 Locked

Is this code right? (dinput)

Started by neonoblivion Apr 25, 2004 at 6:09 PM 2 replies 250+ views
Original Post
neonoblivion
neonoblivion
LPDIRECTINPUT lpdi;
LPDIRECTINPUTDEVICE lpdikey;


if (DirectInputCreate(GetModuleHandle(NULL),DIRECTINPUT_VERSION,&lpdi,NULL)!=DI_OK){
      return (1);
}
   //keyboard

if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK){
      return (1);
}

if (lpdikey->SetCooperativeLevel(hwnd,
                DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK){
      return (1);
}

if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK){
     return (1);
}


if (lpdikey->Acquire()!=DI_OK){
      return (1);
}
I know it runs on most systems, but because it crashes on some, and those same systems run the dx demos fine, I thought maybe... edit:fix code format [edited by - neonoblivion on April 25, 2004 7:12:18 PM]
ms291052
ms291052
The only thing that catches my eye right off the bat is that it''s bad practice to use if(blah != DI_OK). Instead use if(FAILED(blah)). See if that helps at all, since it''s possible those functions are returning something else.
neneboricua19
neneboricua19
You need to call SetDataFormat before you call SetCooperativeLevel. Look in the DX SDK. There is a tutorial for DirectInput on how to work with keyboard devices.

neneboricua

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.