// INCLUDES========================================================================
#include <windows.h>
#include <dinput.h>
// EXTERNS=========================================================================
extern HINSTANCE hinstance;
extern HWND hwnd;
extern UCHAR buffer[256];
// GLOBALS=========================================================================
LPDIRECTINPUT7 g_DI;
LPDIRECTINPUTDEVICE7 g_KDIDev;
HRESULT error;
// FUNCTIONS=======================================================================
///////////////////////////////////////////////////////////////////////////////////
// InitDI - Turns on Direct Input //
///////////////////////////////////////////////////////////////////////////////////
BOOL InitDI()
{
// Create Direct Input Object
if ( DirectInputCreateEx( hinstance, DIRECTINPUT_VERSION, IID_IDirectInput7, (void**)&g_DI, NULL ) )
{
return(FALSE);
}
// Create The Keyboard Device
if ( g_DI->CreateDeviceEx( GUID_SysKeyboard, IID_IDirectInputDevice7, (void**)&g_KDIDev, NULL ) )
{
return(FALSE);
}
// Set Keyboard Data Format
error = g_KDIDev->SetDataFormat(&c_dfDIKeyboard);
if (error)
{
return FALSE;
}
// Set CoOp Level (with windows not players)
error = g_KDIDev->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE );
if (error)
{
return FALSE;
}
if (g_KDIDev)
{
g_KDIDev->Acquire();
}
else
{
return FALSE;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////////////
// ShutdownDI - Shuts Off Direct Input (duh!) //
/////////////////////////////////////////////////////////////////////////////////////
void ShutdownDI()
{
if (g_DI)
{
if (g_KDIDev)
{
g_KDIDev->Unacquire();
g_KDIDev->Release();
g_KDIDev = NULL;
}
g_DI->Release();
g_DI = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////////////
// RefreshKeyBoard - Gets Keyboard State //
/////////////////////////////////////////////////////////////////////////////////////
void RefreshKeyBoard()
{
g_KDIDev->GetDeviceState(256, buffer);
}
|
🔒 Locked
Ah Direct Input!
Advertisement
Original Post
Still no luck.
I''m useing DX 7a.
Anyone heard of some errors in Direct Input 7a?
Anyone heard of some errors in Direct Input 7a?
In those if statements of yours you should be putting != DI_OK or != S_OK after each one, which is in fact zero, so your current function returns immediately whenever a call is sucessful.
Please state the nature of the debugging emergency.
Please state the nature of the debugging emergency.
Firstly ALWAYS use HRESULTs ... they make life so much easier ...
Then You can go
HRESULT hr = S_OK;
hr = g_DI->CreateDeviceEx( GUID_SysKeyboard, IID_IDirectInputDevice7, (void**)&g_KDIDev, NULL );
if ( FAILED( hr ) )
return FALSE;
But the main problem is that you have written gibberish. You are testing the exit code to see if it non-zero ... unfortunately S_OK IS 0! So your code will return false if the function succeeds. I suspect this is the root of all your problems.
Microsoft provide 2 standard macros for dealing with HRESULTs
SUCCEEDED( hr ) and FAILED( hr )
surprisingly the dirst returns true if the function "succeeded" and the second returns true if the function "failed".
Using these macros is probbaly the safest way of working it because they will ALWAYS work even if MS change the HRESULTs about.
Goz
Then You can go
HRESULT hr = S_OK;
hr = g_DI->CreateDeviceEx( GUID_SysKeyboard, IID_IDirectInputDevice7, (void**)&g_KDIDev, NULL );
if ( FAILED( hr ) )
return FALSE;
But the main problem is that you have written gibberish. You are testing the exit code to see if it non-zero ... unfortunately S_OK IS 0! So your code will return false if the function succeeds. I suspect this is the root of all your problems.
Microsoft provide 2 standard macros for dealing with HRESULTs
SUCCEEDED( hr ) and FAILED( hr )
surprisingly the dirst returns true if the function "succeeded" and the second returns true if the function "failed".
Using these macros is probbaly the safest way of working it because they will ALWAYS work even if MS change the HRESULTs about.
Goz
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement