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

dinput AGAIN

Started by xtrmntr Nov 20, 2000 at 3:15 PM 4 replies 300+ views
Original Post
xtrmntr
xtrmntr
does anyone have a "working" sample of DX7 dinput initialization code? if so im in desperate need as the samples in the SDK give me the same compile error when compiling them . any help would save my sanity (or whats left of it)
Cygon
Cygon
Then you didn''t set up your VC directories correctly.
All examples are guaranteed to compile fine if you set the DX paths before the MSVC paths under Menu "Extras" -> Item "Options" -> Tab "Directories".

You can also download my TrueFX library at
www.LunaticSystems.de/truefx
as it contains a complete DirectInput implementation supporting key-binding and cursored text input.

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
wazoo69
wazoo69
what kind of compile error do you get??? Here''s what I''ve used..

(don''t forget to link to dinput.lib and dxguid.lib)..

#include dinput.h

LPDIRECTINPUT7 g_pDI;
LPDIRECTINPUTDEVICE7 g_pKeyboard;

BOOL createDI(HINSTANCE hInst, HWND hWnd){

HRESULT hr;

hr = DirectInputCreateEx(hInst, DIRECTINPUT_VERSION,
IID_IDirectInput7, (void**)&g_lpDI, NULL);
if(FAILED(hr)){
//error code here
return FALSE;
}

hr = g_lpDI->CreateDeviceEx(GUID_SysKeyboard, IID_IDirectInputDevice7,
(void**)&g_pKeyboard, NULL);
if(FAILED(hr)){
//return error and cleanup
destroyDI();
return FALSE;
}

hr = g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
if(FAILED(hr)){
//return Error
destroyDI();
return FALSE;
}

hr = g_pKeyboard->SetCooperativeLevel(hWnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if(FAILED(hr)){
destroyDI();
return FALSE;
}

g_pKeyboard->Acquire();

return TRUE;
}



void destroyDI(){

if(g_pKeyboard){

g_pKeyboard->Unacquire();
g_pKeyboard->Release();
g_pKeyboard = NULL;
}
}


That''s all I use and it works just fine for me..

Wazoo


xtrmntr
xtrmntr
i get a compile error saying the DirectInputCreateEx is an 'undeclared variable', WTF is up with that!? (DX8 input compiles fine but why the hell would i use DX7 for everything but input? (my directories are setup correctly and i include dinput.h) i get this same error when trying to compile the SDK samples. i hope someone can spot the problem

edit: btw i have tried linking to the DX7 AND DX8 libs with no luck with either.

here is the line the error appears on:

if(DirectInputCreateEx(hinst, DIRECTINPUT_VERSION, IID_IDirectInput7, (VOID **)&lpdi, NULL) != DI_OK)
return FALSE;

Edited by - xtrmntr on November 20, 2000 5:02:32 PM

Edited by - xtrmntr on November 20, 2000 5:27:05 PM
xtrmntr
xtrmntr
WHY GOD? WHY!?!?!?!?!?!?!?!?!?!!?
xtrmntr
xtrmntr
i finally figured out HOW to fix it but still incredibly confused about WHY it fixed it.

i have a precompiled header containing includes that are needed in multiple files i.e. ddraw.h, dinput.h, etc.

this header file is included in my dinput setup stuff so you would think that would be just fine. i mean i did the same thing with my ddraw stuff and it works great. here is how the precompiled header looked before:

#include
#include
#include
#include
#include
#include "ddtools.h"
#include "ditools.h"
#include "graphics.h"

and i was gretting the error DirectInputCreateEx is an undeclared variable. i switch the header file to this and it compiles fine.

#include
#include
#include
#include
#include "ddtools.h"
#include
#include "ditools.h"
#include "graphics.h"

does anyone have the slightest clue as to why that fixed it cause i''d love to know.

well that was a complete waste of a full day of learning

Topic Locked

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

Sign in to reply to this topic.