# 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.

## 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 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 on other sites
DirectX is totally object oriented though, implementing the COM model, so you do NOT want to try and use it in C.

##### Share on other sites
Quote:
 Original post by tok_juniorDirectX 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.

1. 1
2. 2
Rutin
23
3. 3
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013158
×