Jump to content
  • Advertisement
Sign in to follow this  
beerham

DirectInput and C

This topic is 4171 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; 
	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++.

Share this post


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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!