Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stuck on DirectInput

Started by PoLiSh_Peta Jan 31, 2004 at 2:16 PM 3 replies 1.1k views
Original Post
PoLiSh_Peta
PoLiSh_Peta
Hello, I''m using the SDK to help me make the input portion of my engine, and I''m done with the keyboard. I''m stuck on Step 4: Preparing for Buffered Input from the Mouse for the mouse portion of the input system. What in the world is "Scrawl" and what is this variable: g_hMouseEvent? Is g_hMouseEvent the DIMOUSESTATE structure or what? Thanks. -Peter
There are two inevitabilities in life: death and failure.-PoLiSh
neneboricua19
neneboricua19
Scrawl is a DirectInput sample that comes with the SDK.

I haven''t looked at the code, but I suspect that g_hMouseEvent is a HANDLE variable declared at global scope.

neneboricua
jacklin
jacklin
g_hMouseEvent is the handle to a Win32 event object. DirectInput devices support event notification so that your application can call WaitForSingleObject() and get notified when the state of the device changes (the mouse is moved or a button is clicked).

Look up the IDirectInputDevice8::SetEventNotification reference page in the SDK documentation for more detailed information.
PoLiSh_Peta
PoLiSh_Peta
I'll hold off on the mouse portion of the input. I'm getting 40 errors in just the input portion of my engine. It's really weird.

This file holds all the includes and such.
GlobalClass.h

#ifndef GlobalHeader_H_
#define GlobalHeader_H_

#include <windows.h>
#include <d3dx9.h>
#include <dinput.h>

#include "Input.h"
#include "Application.h"


#endif


Input.h//The private section of this class has a lot of the errors.What's up with that?
   
#ifndef Input_H_
#define Input_H_


typedef unsigned char UCHAR;
#define SafeRelease(x) if (x) {x->Release(); x=NULL;}

class cINPUT
{
public:

//The constructor will call several other functions to create the entire

//input system. Destructor will call all the respective functions to

//shutdown the entire input system.


cINPUT();
~cINPUT();

//This is called in the constructor. This will create the keyboard device,

//set the data format for the device, and set the behavior (cooperative

// level), and acquire the device as well.

BOOL CreateKeyboardDevice();
//Process the input from the keyboard.

void ProcessKeyboardInput();

//This is called in the constructor. This will create the mouse device,

//set the data format for the device, and set the behavior (cooperative

// level), and acquire the device as well.

BOOL CreateMouseDevice();


private:

HRESULT hr;
LPDIRECTINPUT8 MainDIObject;
LPDIRECTINPUTDEVICE8 Keyboard;
LPDIRECTINPUTDEVICE8 Mouse;

//Buffer to hold input from the keyboard.

char buffer[ 256 ];
};

#endif

Heres just a few of the errors:
error C2501: 'LPDIRECTINPUT8' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'Mouse'


Input.cpp
   
#include "GlobalClass.h"

cINPUT::cINPUT()
{
//Creates the main DirectInput8 object.

hr = DirectInput8Create( Instance_Handle,
DIRECTINPUT_VERSION,
IID_IDirectInput8,
( void** ) &MainDIObject,
NULL );

CreateKeyboardDevice();
}

BOOL cINPUT::CreateKeyboardDevice()
{
hr = MainDIObject->CreateDevice( GUID_SysKeyboard, &Keyboard, NULL );

hr = Keyboard->SetDataFormat( &c_dfDIKeyboard );

hr = Keyboard->SetCooperativeLevel( WindowHandle,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );

if( Keyboard ) Keyboard->Acquire();

return TRUE;
}

void cINPUT::ProcessKeyboardInput()
{
#define KEYDOWN( name, key ) ( name[key] & 0x80 )

hr = Keyboard->GetDeviceState( sizeof( buffer ),( LPVOID ) &buffer );

//Here is where we will make the appropriate actions in the game based

//one what is inputed. This form should do:


/*
if( KEYDOWN( buffer, DIK_RIGHT ) );
Turn right.
*/

}

/*BOOL cINPUT::CreateMouseDevice()
{
hr = MainDIObject->CreateDevice( GUID_SysMouse, &Mouse, NULL );

hr = Mouse->SetDataFormat( &c_dfDIMouse );

hr = Mouse->SetCooperativeLevel( WindowHandle,
DISCL_EXCLUSIVE | DISCL_FOREGROUND );





This has a bunch of errors all over the place, and seem to be related to DirectInput stuff, such as:
c:\documents and settings\owner\desktop\anomaly engine\input.cpp(21) : error C2227: left of '->SetCooperativeLevel' must point to class/struct/union

hr = DirectInput8Create( Instance_Handle,


I really need some help.

-Peter

[edited by - PoLiSh_Peta on January 31, 2004 6:16:59 PM]

[edited by - PoLiSh_Peta on January 31, 2004 6:18:54 PM]
There are two inevitabilities in life: death and failure.-PoLiSh
jacklin
jacklin
It seems that the wrong version of dinput.h is getting included. Either hardcode the header path in #include or ensure that the compiler searches the DirectX SDK directory first for headers.

Topic Locked

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

Sign in to reply to this topic.