Thread: DirectInput and Dev-C++

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291

    DirectInput and Dev-C++

    Hello, recently I have started to learn directX, using the Dev-cpp IDE with MingW. For the lessons and samples about Direct3D theres no problem (all works fine), but when I start with DirectInput it seems that something isn't working properly (or maybe I fail to include-link-define something. That is what I do: I set up the linker options with all the libs (*.a in devcpp) that the 'setup dev-cpp for dx' manual says (libd3d8.a, libd3dx8d.a, libgdi32.a, libdxguid.a, libddraw.a, libdinput.a, libdinput8.a, also the winmm.a for the timeGetTime() function); then I use
    Code:
    #define INITGUID
    #define STRICT
    #define WIN32_LEAN_AND_MEAN
    #define DIRECTINPUT_VERSION 0x0800
    #include <windows.h>
    #include <D3DX8.h>
    #include <dinput.h>
    Then I use some structures for the DirectInput object and devices:
    Code:
    LPDIRECTINPUT8          g_lpdi       = NULL; // DirectInput object
    LPDIRECTINPUTDEVICE8    g_pKeyboard  = NULL; // DirectInput device for keyboard
    LPDIRECTINPUTDEVICE8    g_pMouse     = NULL; // DirectInput device for mouse
    but on de compilation it appears the error "syntax error before '='" referred to those 3 lines above, even if I declare them as 'LPDIRECTINPUT8 g_lpdi;' the error is "syntax error before ';'", so that means that the 'LPDIRECTINPUT8' is not defined (no?); I have opened the dinput.h include file from the DX8 includes dir inside the 'includes' dir of dev-cpp, and there is that
    structure declared as
    Code:
     
    typedef struct IDirectInput8 *LPDIRECTINPUT8;
    I have find another similar structures named 'LPDIRECTINPUT', 'LPDIRECTINPUTDEVICE', I tried to work with them and there's any error, the program is right compiled.
    Then continuing with the DirectInput lesson I have to set up the object, using the 'DirectInput8Create()' function, using the next code:
    Code:
    DirectInput8Create(GetModuleHandle(NULL),
                       DIRECTINPUT_VERSION,
                       IID_IDirectInput8,
                       (VOID**)&g_lpdi,
                       NULL);
    but the compiler shows the error "'IID_IDirectInput8' undeclared (first use this function)"; it seems like that function haven't prototype, so I must define previously it: 'void IID_IDirectInput8();', recompile the code and now I haven't the last error but get a new one: "implicit declaration of function `int DirectInput8Create(...)'"; I research inside dinput.h and there is that function:
    Code:
    #if DIRECTINPUT_VERSION > 0x0700
    
    extern HRESULT WINAPI DirectInput8Create(HINSTANCE hinst,
    					 DWORD dwVersion,
    					 REFIID riidltf,
    					 LPVOID *ppvOut,
    					LPUNKNOWN punkOuter);
    
    #else
    extern HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst,
    					 DWORD dwVersion,
    					 LPDIRECTINPUTA *ppDI,
    					 LPUNKNOWN punkOuter);
    extern HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst,
    					 DWORD dwVersion,
    					 LPDIRECTINPUTW *ppDI,
    					 LPUNKNOWN punkOuter);
    #ifdef UNICODE
    #define DirectInputCreate  DirectInputCreateW
    #else
    #define DirectInputCreate  DirectInputCreateA
    #endif
    ok, as far as I defined '#define DIRECTINPUT_VERSION 0x0800' I shoud use that function; I opted to try using 'DirectInputCreate()' instead 'DirectInput8Create()':
    Code:
    DirectInputCreate(GetModuleHandle(NULL),
                       DIRECTINPUT_VERSION,
                       IID_IDirectInput8,
                       (VOID**)&g_lpdi,
                       NULL);
    and now the error is : "passing `void (*)()' as argument 3 of `DirectInputCreateA(HINSTANCE__ *, long unsigned int, IDirectInputA **, IUnknown *)'"; right look at dinput.h I see that I have to use the parameters on 'DirectInputCreateA()' function, so I change all into:
    Code:
    //as a global definition
    LPDIRECTINPUTA *ppDI;
    //and the function
    DirectInputCreate(GetModuleHandle(NULL),
                       DIRECTINPUT_VERSION,
                       ppDI,
                       NULL);
    and there's no compiler errors. For me, it seems a strange thing: all the Direct3D on DX8 works well as the original code (also the samples for DX9 works well with a minimal variations), but DirectInput needs so strange variations?
    Have someone got those problems? Still another, must that direct input creation style affect on the program working? (I have stop here following the lesson, becasue I'm afraid that that modification can cause future problems).
    Thank's in advance, and sorry for the large and boring post
    Niara(vosk)

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You must have:

    #define DIRECTINPUT_VERSION _version_num_

    prior to including dinput.h.

    This will fix your problem.

    Here is a sample from my DirectInput class.
    Code:
    #ifndef CDINPUT
    #define CDINPUT
    
    
    //This is the #define you need prior to including dinput.h
    #define DIRECTINPUT_VERSION 0x0800
    //
    
    
    #include <dinput.h>
    
    class CDInput
    {
        protected:
            IDirectInput8 *_pDI8;
        public:
            CDInput() { };
    		CDInput(HINSTANCE hinst) {Init(hinst);};
            ~CDInput() { };
    
            HRESULT Init(HINSTANCE hinst);
    		void    ShutDown(void) {if (_pDI8) _pDI8->Release();};
    		IDirectInput8 *GetInterface(void) {return _pDI8;};
    };
    #endif
    I, too, had the same problem when I started. I about threw my system out the window until I figured it out. In fact my old post asking about it should be on this board somewhere.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hello Bubba, thank's for your time and code.
    Still gives the same error about not recognizing the 'LPDIRECTINPUT8' and 'LPDIRECTINPUTDEVICE8'; if I try using 'LPDIRECTINPUT' then shows the error about "implicit declaration of function `int DirectInput8Create(...)'" and "'IID_IDirectInput8' undeclared (first use this function)".
    I think that some fault is mine, because I'm not very introduced on working with c++ classes (I do it as a hobby, and never before I had used c++ to create a game, only C & Allegro).
    I think that I already have read your old post, something about commctrl.h (hope I'm not mixed), and I have also included de commctrl.h, link the compiler with the devcpp libcomctl32.a, and started the 'InitCommonContrls();' but I can see any difference (still the same error).
    Finally I have tried to evaluate the keyboard keys from the window process switching the message case WM_KEYDOWN and searching for the up-down-right-left keys, but is not the same (with that method there's a little delay before get a fluid key sequence).
    Did you get also the same problem with 'LPDIRECTINPUT8' and 'LPDIRECTINPUTDEVICE8'?
    Thank you
    Niara(vosk)

Popular pages Recent additions subscribe to a feed