[c#]USB接続デバイス管理 5-『setupapi.dll』メソッド実装

構造体の定義付を行ったので『setupapi.dll』のメソッドを実装します。

        // 読込dll
        private const string setupapi = "setupapi.dll";
        ※念のため[C:\\Windows\\System32\\setupapi.dll]を値として使用した方が良いかも知れません。
        //外部dllメソッド
        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiCallClassInstaller(Function function, IntPtr deviceIntPtr, ref DeviceInfoData deviceInfo);

        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiEnumDeviceInfo(IntPtr deviceIntPtr, int index, ref DeviceInfoData deviceInfo);

        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern SafeDeviceInfoSetHandle SetupDiGetClassDevs(ref Guid guid, IntPtr enumerator, IntPtr parent, SetupFlag flag);

        [DllImport(setupapi, SetLastError = true, CharSet = CharSet.Auto)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiGetDeviceInstanceId(IntPtr deviceIntPtr, ref DeviceInfoData deviceInfo, StringBuilder InstanceId, int IdSize, out int RequiredSize);

        [SuppressUnmanagedCodeSecurity()]
        [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);

        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiSetClassInstallParams(IntPtr deviceIntPtr, ref DeviceInfoData deviceInfo, ref PropertyParameters InstallParams, int ParamsSize);

        [DllImport(setupapi, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetupDiChangeState(IntPtr deviceIntPtr, [In()]ref DeviceInfoData deviceInfo);

【各ページへのリンク】

この記事へのコメント