Skip to content

Conversation

@Valkirie
Copy link

C# implementation has to be:

[DllImport("JoyShockLibrary")]
public static extern JOY_SETTINGS JslGetControllerInfoAndSettings(int deviceId);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct JOY_SETTINGS
{
	public int gyroSpace;
	public int colour;
	public int playerNumber;
	public int controllerType;
	public int splitType;
	[MarshalAs(UnmanagedType.U1)]
	public bool isCalibrating;
	[MarshalAs(UnmanagedType.U1)]
	public bool autoCalibrationEnabled;
	[MarshalAs(UnmanagedType.U1)]
	public bool isConnected;
	[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
	public string path;
}

@JibbSmart
Copy link
Owner

Thanks for this!

Just because a long string adds a lot to the size of JOY_SETTINGS, I think it'd be better to have a dedicated function for getting the string. The caller would give it a char array and the length of the array, and the function would fill the array with the path up to the given length.

Would you be up for giving that a go?

@Valkirie
Copy link
Author

I could implement a dedicated function I guess. The only "issue" is that I'm not sure we can guess the hid path size in advance. Bluetooth devices have a longer path than wired devices. I'll investigate.

@JibbSmart
Copy link
Owner

It doesn't need to know the size in advance, just have an array that's big enough. Just like how you pre-allocated 256 in the JOY_SETTINGS version, the caller could say "it's probably not more than 256 bytes" and use an array that big.

I think this is a common pattern for strings in C. Commonly, something like this would also return an int that's the length of the actual string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants