DLL Help

I have a small problem concerning my DLL I have created. I have had one or two people test my DLL, although my results aren't as expected since I cannot test all the features myself.

I'd like some help reviewing the code itself as well as finding some people to test it out on my topic here: http://www.cplusplus.com/forum/general/113532/

My known problems so far are that the "dwRpos" and "dwZpos" as well as the Y-Axis("joyVpos") on the right joystick function don't work.

DLL Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//Controller: Return USB Controller Input
#include <Windows.h>
#define EXPORT extern "C" _declspec( dllexport )
#pragma comment( lib , "Winmm.lib" )
JOYINFOEX joystick[ 16 ];

//Controller: Initiate JOYINFOEX Data.
void JoyCheck( double joyid ) {
	if ( joystick[ int( joyid ) ].dwSize == false ) {
		joystick[ int( joyid ) ].dwSize = sizeof( JOYINFOEX );
		joystick[ int( joyid ) ].dwFlags = JOY_RETURNALL;
	}
}

//Controller: Check If Joystick Is Plugged In.
EXPORT double JoystickPlugged( double joyid ) {
	JoyCheck( joyid );

	bool joy = joyGetPosEx( UINT( joyid )  , &joystick[ int( joyid ) ] ) == JOYERR_NOERROR;
	return double( joy );
}

//Controller: Buttons Up To 1-32.
EXPORT double JoystickButtons( double joyid , double button ) {
	JoyCheck( joyid );
	return double( joystick[ int( joyid ) ].dwButtons & ( 1 << int( button ) ) );
}

//Controller: Left Joystick + Left Joystick Button.
EXPORT double JoystickJStickL( double joyid , double mode ) {
	JoyCheck( joyid );

	double joyXpos = double( joystick[ int( joyid ) ].dwXpos );
	double joyYpos = double( joystick[ int( joyid ) ].dwYpos );
	double joyZpos = double( joystick[ int( joyid ) ].dwZpos );

	switch( int( mode ) ) {
		case 0:
			return ( ( joyXpos == 65535 ) * 1 ) + ( ( joyXpos == 32511 ) * 0 ) + ( ( joyXpos == 0 ) * -1 );
		break;
		
		case 1:
			return ( ( joyYpos == 65535 ) * 1 ) + ( ( joyYpos == 32511 ) * 0 ) + ( ( joyYpos == 0 ) * -1 );
		break;
			
		case 2:
			return ( ( joyZpos == 1 ) * 1 ) + ( ( joyZpos == 0 ) * 0 );
		break;

		default:
			return -4;
		break;
	}
}

//Controller: Right Joystick + Right Joystick Button.
EXPORT double JoystickJStickR( double joyid , double mode ) {
	JoyCheck( joyid );

	double joyUpos = double( joystick[ int( joyid ) ].dwUpos );
	double joyVpos = double( joystick[ int( joyid ) ].dwVpos );
	double joyRpos = double( joystick[ int( joyid ) ].dwRpos );

	switch( int( mode ) ) {
		case 0:
			return ( ( joyUpos == 65535 ) * 1 ) + ( ( joyUpos == 32511 ) * 0 ) + ( ( joyUpos == 0 ) * -1 );
		break;
		
		case 1:
			return ( ( joyVpos == 65535 ) * 1 ) + ( ( joyVpos == 32511 ) * 0 ) + ( ( joyVpos == 0 ) * -1 );
		break;
		
		case 2:
			return ( ( joyRpos == 1 ) * 1 ) + ( ( joyRpos == 0 ) * 0 );
		break;
		default:
			return -4;
		break;
	}
}
Last edited on
Why are all your parameters double when you clearly have bool, unsigned, and enum, ...

You should consider using stdcall rather than cdecl as your calling convention as you don't need variadic functions.

joyid is clearly some kind of handle, but I don't see where it's created/deleted. And again, you're passing it as a double.
Last edited on
All the double conversions are due to this is used for Game Maker. Although I think I might have over did it, which I will be fixing, although it's not really a problem to use double values. I am using stdcall rather than cdecl.

Joyid, Button and Mode are all values retrieved from when the functions are called. For example you'd call function JoystickPlugged( 0 ) in order to check if the first joystick is plugged in and ready for use. Joyid is a value of 0-15, Button is a value of 0-31 and Mode is 0-2.

EDIT: I might be confused here, but what exactly are the dwUpos, dwVpos and dwVpos supposed to be compared to X, Y and Z?
Last edited on
what exactly are the dwUpos, dwVpos and dwVpos
http://msdn.microsoft.com/en-us/library/windows/desktop/dd757112%28v=vs.85%29.aspx

According to that GML file, you should be using stdcall.
1
2
3
4
5
6
7
8
9
10
#define Joy_Initiate globalvar JoystickPlugged , JoystickButtons , JoystickStick , JoystickCurrent; \
 JoystickPlugged = external_define( "JoyStick.dll" , "JoystickPlugged" , dll_stdcall , ty_real , 1 , ty_real ); \
 JoystickButtons = external_define( "JoyStick.dll" , "JoystickButtons" , dll_stdcall , ty_real , 2 , ty_real , ty_real ); \
 JoystickJStickL = external_define( "JoyStick.dll" , "JoystickJStickL" , dll_stdcall , ty_real , 2 , ty_real , ty_real ); \
 JoystickJStickR = external_define( "JoyStick.dll" , "JoystickJStickR" , dll_stdcall , ty_real , 2 , ty_real , ty_real );
#define Joy_Plugged return external_call( JoystickPlugged , argument0 );
#define Joy_Buttons return external_call( JoystickButtons , argument0 , argument1 );
#define Joy_JStickL return external_call( JoystickJStickL , argument0 , argument1 );
#define Joy_JStickR return external_call( JoystickJStickR , argument0 , argument1 );
#define Joy_Close external_free( "JoyStick.dll" ); 

s for the stdcall I am not 100% if it should be cdecl or stdcall. I originally used stdcall since the function joyGetPosEx() says that stdcall is it's call type:
"MMRESULT _stdcall joyGetPosEx(...)"

The MS documentation doesn't explain enough.
What is rudder and how does it differ from the X, Y and Z axis'? I think I might have the U, V and R switch though. In the switch statement it should go: R, U and V last. That might actually be my problem.

Although what is the Z axis? I was thinking this was the joystick button press(E.g. L3 or R3). Is that true?
Last edited on
Topic archived. No new replies allowed.