use joystick with program?

Hi I would like to somehow use a controller with my program. The code below is what I've tried to compile from this site

http://msdn.microsoft.com/en-us/library/ms713447.aspx

in Getting the Driver Capabilities

here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include<stdio.h>
#include<Windows.h>


int main()
{
	
	JOYINFO joyinfo; 
	UINT wNumDevs, wDeviceID; 
	BOOL bDev1Attached, bDev2Attached; 
	
	if((wNumDevs = joyGetNumDevs()) == 0) 
		return ERR_NODRIVER; 
	bDev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED; 
	bDev2Attached = wNumDevs == 2 && joyGetPos(JOYSTICKID2,&joyinfo) != JOYERR_UNPLUGGED; 
	if(bDev1Attached || bDev2Attached)   // decide which joystick to use 
		wDeviceID = bDev1Attached ? JOYSTICKID1 : JOYSTICKID2; 
	else
		return ERR_NODEVICE;
}


every time I build i get this
1
2
3
4

1>c:\users\cyberpirate\documents\visual studio 2010\projects\gamepad test\gamepad test\maincode.cpp(13): error C2065: 'ERR_NODRIVER' : undeclared identifier
1>c:\users\cyberpirate\documents\visual studio 2010\projects\gamepad test\gamepad test\maincode.cpp(19): error C2065: 'ERR_NODEVICE' : undeclared identifier


I think I'm missing an include, if so which one?
Last edited on
I think you are looking for mmsystem.h (make sure it's after windows.h)...

That's what it said on an MSDN site...
nope I put that in the #include and I got the same errors
Well, since you are just returning main, then don't worry about it at all. Either make it up yourself, or return a 1 or something instead. I've found online people defining it, but don't really want to keep searching for this... define the values yourself in an enum or a #define or something...
well the only problem with that is I get these errors

1
2
3
4

1>MainCode.obj : error LNK2019: unresolved external symbol __imp__joyGetPos@8 referenced in function _main
1>MainCode.obj : error LNK2019: unresolved external symbol __imp__joyGetNumDevs@0 referenced in function _main


I didn't do this before because I have no idea what those are saying and I figured it would just be easier to find the include file
that's a linker error...

http://msdn.microsoft.com/en-us/library/dd757107%28v=vs.85%29.aspx

you need to link Winmm.lib
Ok it compiled. Thanks!
Topic archived. No new replies allowed.