JoyShockLibrary icon indicating copy to clipboard operation
JoyShockLibrary copied to clipboard

Missing Calling Convention in JoyShockLibrary.cs

Open michaelarts opened this issue 4 years ago • 2 comments

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.

michaelarts avatar Aug 14 '20 16:08 michaelarts

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;
        }

michaelarts avatar Aug 14 '20 17:08 michaelarts

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 👍

JibbSmart avatar Aug 20 '20 05:08 JibbSmart