Jump to content
  • Advertisement
Sign in to follow this  

DirectInput and C

This topic is 4251 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; 
	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++.

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!