JoyShockLibrary
JoyShockLibrary copied to clipboard
Missing Calling Convention in JoyShockLibrary.cs
Hello,
I'm currently plugging this into a MonoGame project and received an error when calling JslGetConnectedDeviceHandles(). I was able to fix the crash by making the following change:
[DllImport("JoyShockLibrary"]
public static extern int JslGetConnectedDeviceHandles(int[] deviceHandleArray, int size);
to
[DllImport("JoyShockLibrary", CallingConvention = CallingConvention.Cdecl)]
public static extern int JslGetConnectedDeviceHandles(int[] deviceHandleArray, int size);
Thanks for sharing this awesome library!
EDIT: This fix was also required for the function JslGetControllerType(). I'm assuming that all the functions need the CallingConvention.Cdecl line.
Also, I don't have much experience with bit manipulation so it took me a while to figure out how to check the buttons. I'd like to suggest that an example is shown on the wiki, or maybe even a helper function could be included in the .cs class!
This is what I'm using:
bool IsBitSet(int bit, int mask)
{
return (bit & (1 << mask)) != 0;
}
Thanks for the feedback. I don't know why it's needed with MonoGame. It hasn't been a problem with me in Unity. Also, good idea about adding examples. I'll come back to this later, but I think it's a good suggestion 👍