简体   繁体   中英

Get device (joystick) guid with windows multimedia (winmm.dll)

I try to implement interoperating with unmanaged code and c#.

I've decided to use winmm.dll for this.

There is need for get joystick unique guid and identify devise status (connected or not)

After some investigation i believe that founded out function that should to do it ( joyGetDevCapsA ). But there is not clear what value should be pass as 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);
    }

There is not lot information about winmm API for C# thought internet, so if someone have experience please share it.

Q: How can be detected attached or not joystick at current moment and get device unique Guid?

According to the @Hans Passant ( https://stackoverflow.com/users/17034/hans-passant ) comments below question:

There is no guid, there is no connection state. The specific joystick is identified with a simple uint. 0 is the first joystick, 1 is the second, etc.

It works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM