Skip to main content
gamedev.net
🔒 Locked

DirectInput8Create() not working

Started by lack the hack 2 replies 3.1k views
Original Post
lack the hack
lack the hack
hello i've been trying to get DirectInput to work for a while, but to no avail. when i call DirectInput8Create() and it says syntax error 'constant', this is the code im using

#ifndef directInput_h
#define directInput_h

#include <windows.h>
#include <dinput.h>
HRESULT result;

HRESULT WINAPI DirectInput8Create(HINSTANCE g_hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, LPDIRECTINPUT8 *pDirectInput, NULL);




#endif

whats a matter with this code? thanks a bunch:-)
HeavyBlade
HeavyBlade
Well for a start, you really shouldn't be redefining a DirectInput function, which is what you appear to be doing. Are you sure you have the right libs in place?

Second, it also looks like you didn't define DIRECTINPUT_VERSION, which the directX libs require you to define yourself - this tells it what version of DirectInput to include/utilize. For example, for the latest version of directX, just include the following:

#define DIRECTINPUT_VERSION 0x0800

and you'll need to place this definition *before* including the directinput header. Otherwise, it won't know what version to look for.

But, an undefined variable like that, would definitely cause your problem.
...edit, also make sure you're including the dxguid.lib library - that contains the definition for your IID_IDirectInput8.
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
lack the hack
lack the hack
alright, thanks a bunch:-)
That got rid of a lot of warnings that my compiler was giving me. the only things that's giving me a problem now is that it says: error C2059: syntax error : 'constant', even though there are no constants in my header file. what could be the problem here?
HeavyBlade
HeavyBlade
Well, as I said before, why are you redefining the DirectInputCreate function?
You'd want one of the following:

// This is a function prototype, but DirectInput8Create is already defined in // DInput.h/lib.
HRESULT WINAPI DirectInput8Create(HINSTANCE g_hInstance, (DIRECTINPUT_VERSION's type) DIRECTINPUT_VERSION, (IID_IDirectInput8's type) IID_IDirectInput8, LPDIRECTINPUT8* pDirectInput);

Or, this:

// This is a function call. Never place an object's data type beside it in here.
DirectInput8Create(g_hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, pDirectInput);

Right now, you basically have half of both, and so your compiler is treating the parameters of the function call as constants because it doesn't have them correctly predefined.

Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!

Topic Locked

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

Sign in to reply to this topic.