DirectInput and C

Started by
4 comments, last by beerham 16 years, 12 months ago
hi, i'm trying to compile a few simple lines of code with the newest dxsdk.
#include <windows.h>
#include <dinput.h>




int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HRESULT         hr; 
	LPDIRECTINPUT8  g_lpDI; 
	hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_lpDI, NULL); 
	return 0;
}
unfortunately i'm getting this errormessage: C:\Program Files\Microsoft DirectX SDK (April 2007)\Include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800 dinput.c(12) : error C2440 'function' : cannot convert from 'const GUID' to 'const IID *const' dinput.c(12) : warning C4024: 'DirectInput8Create' : different types for formal and actual parameter 3 when i rename dinput.c to dinput.cpp the code compiles without problems. what do i have to do, to use the inputfunctions with c? i tried to google but all tutorials i have found focus on directinput with c++.
Advertisement
Does this other thread help? DIRECTINPUT_VERSION undefined. Defaulting to version 0x080
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
LessBread is correct on the first error. The second error is because C doesn't support references, so the code compiles differently, expecting a GUID pointer instead of a reference. When you rename the file to .cpp, it compiles as C++ code, which can use references.

So, if you want to use a .c file, you need to change the line to:
hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8, (void**)&g_lpDI, NULL);
(I think, untested).
DirectX is totally object oriented though, implementing the COM model, so you do NOT want to try and use it in C.
Quote:Original post by tok_junior
DirectX is totally object oriented though, implementing the COM model, so you do NOT want to try and use it in C.
I agree. C++ would be much more suitable. However, it is still possible to use C if you have to (DirectX has C methods for accessing the COM objects).
thank you.

This topic is closed to new replies.

Advertisement