c#中windows Ce 6.0上usb的序列号

本文关键字:usb 序列号 windows Ce | 更新日期: 2023-09-27 17:54:02

我需要获得连接到windows ce 6.0设备的usb棒的序列号。我尝试了KernelIoControl,我得到了windows ce 6.0设备的序列号,但没有连接到它的usb。

    private static string GetDeviceID()
    {
        // Initialize the output buffer to the size of a  
        // Win32 DEVICE_ID structure. 
        byte[] outbuff = new byte[20];
        Int32 dwOutBytes;
        bool done = false;
        Int32 nBuffSize = outbuff.Length;
        // Set DEVICEID.dwSize to size of buffer.  Some platforms look at 
        // this field rather than the nOutBufSize param of KernelIoControl 
        // when determining if the buffer is large enough.
        BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
        dwOutBytes = 0;
        // Loop until the device ID is retrieved or an error occurs. 
        while (!done)
        {
            if (KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero,
                0, outbuff, nBuffSize, ref dwOutBytes))
            {
                done = true;
            }
            else
            {
                int error = Marshal.GetLastWin32Error();
                switch (error)
                {
                    case ERROR_NOT_SUPPORTED:
                        throw new NotSupportedException(
                            "IOCTL_HAL_GET_DEVICEID is not supported on this device",
                            new Win32Exception(error));
                    case ERROR_INSUFFICIENT_BUFFER:
                        // The buffer is not big enough for the data.  The 
                        // required size is in the first 4 bytes of the output 
                        // buffer (DEVICE_ID.dwSize).
                        nBuffSize = BitConverter.ToInt32(outbuff, 0);
                        outbuff = new byte[nBuffSize];
                        // Set DEVICEID.dwSize to size of buffer.  Some 
                        // platforms look at this field rather than the 
                        // nOutBufSize param of KernelIoControl when 
                        // determining if the buffer is large enough.
                        BitConverter.GetBytes(nBuffSize).CopyTo(outbuff, 0);
                        break;
                    default:
                        throw new Win32Exception(error, "Unexpected error");
                }
            }
        }

当我将usb棒连接到windows ce 6设备时,它显示我一个新的硬盘识别,我需要来注册这个新设备的属性,控制我的windows ce 6设备上可用的usb端口。

c#中windows Ce 6.0上usb的序列号

您可能要查找的是USB_DEVICE_DESCRIPTOR。在大窗口中,您将使用SetupDiGetDeviceProperty来获取此信息,但在CE中,此值仅对驱动程序可用。我认为没有一种通用的方法可以从CE的驱动程序中获取这些信息。但是,您的驱动程序可能包含一个特殊的IOCTL_来获取该信息。