我尝试实现与非托管代码和C#的互操作。
我已决定为此使用winmm.dll。
需要获得操纵杆唯一的GUID并识别设备状态(是否连接)
经过一些调查,我相信应该建立应该执行的功能(joyGetDevCapsA)。但是尚不清楚应将什么值作为int id parameter
传递public static class InputControllerInteroperator
{
private const string WINMM_NATIVE_LIBRARY = "winmm.dll";
private const CallingConvention CALLING_CONVENTION = CallingConvention.StdCall;
[DllImport(WINMM_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]
public static extern int joyGetPosEx(int uJoyID, ref JOYINFOEX pji);
[DllImport(WINMM_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]
public static extern int joyGetPos(int uJoyID, ref JOYINFO pji);
[DllImport(WINMM_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]
public static extern int joyGetNumDevs();
[DllImport(WINMM_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION, EntryPoint = "joyGetDevCaps"), SuppressUnmanagedCodeSecurity]
public static extern int joyGetDevCapsA(int id, ref JOYCAPS lpCaps, int uSize);
}
关于用于C#的Internet的winmm API的信息不多,所以如果有人有经验,请分享。
Q:如何在当前时刻检测是否已连接操纵杆并获得设备唯一的Guid?
根据以下问题的@ Hans Passant(https://stackoverflow.com/users/17034/hans-passant)评论:
没有向导,没有连接状态。特定的操纵杆用简单的uint标识。 0是第一个操纵杆,1是第二个操纵杆,依此类推。
对我有用