Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SetupDiGetDeviceInterfaceDetail无法解释的错误_C#_.net_Usb - Fatal编程技术网

C# SetupDiGetDeviceInterfaceDetail无法解释的错误

C# SetupDiGetDeviceInterfaceDetail无法解释的错误,c#,.net,usb,C#,.net,Usb,这一次我有一个错误,我一直在试图找出它存在的原因。虽然这个错误可以忽略,但我想知道为什么它会出现在第一位 result = SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref anInterface, IntPtr.Zero, 0, ref buffersize, IntPtr.Zero); if (!result) { int errCode = Marshal.G

这一次我有一个错误,我一直在试图找出它存在的原因。虽然这个错误可以忽略,但我想知道为什么它会出现在第一位

result = SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref anInterface, IntPtr.Zero, 0, ref buffersize, IntPtr.Zero);
            if (!result)
            {
                int errCode = Marshal.GetLastWin32Error();
                errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                statusLabel.Text += "\n(1)SetupDiGetDeviceInterfaceDetail Error: " + errCode + " => " + errorMessage + ".";
                //break;
            }
这是对该函数的第一次调用,仅用于为该函数的第二次调用设置buffersize变量。我收到打印的错误消息:122=>传递给系统调用的数据区域太小。 从错误消息判断,我认为这一定与第二个参数(ref-anInterface)有关,我可以忽略第二个过程,结果证明是真的;但是这个错误仍然存在,我想知道为什么在它回来咬我的背后。 所述参数的声明和定义如下:

[StructLayout(LayoutKind.Sequential)] // defined here
    public struct SP_DEVICE_INTERFACE_DATA
    {
        public uint cbSize;
        public Guid InterfaceClassGuid;
        public uint Flags;
        public IntPtr Reserved;
    }

anInterface = new SP_DEVICE_INTERFACE_DATA(); // declared here
        anInterface.cbSize = (uint)Marshal.SizeOf(anInterface);
        anInterface.InterfaceClassGuid = Guid.Empty;
        anInterface.Reserved = IntPtr.Zero;
        anInterface.Flags = 0;

我已经把msdn文章分门别类了,据我所知,这里的代码没有任何问题。

这应该是设计的结果。如果您查看“评论”部分:

使用此函数获取有关接口的详细信息通常需要两个步骤:

1) 获取所需的缓冲区大小。使用空DeviceInterfaceDetailData指针、零DeviceInterfaceDetailDataSize和有效的RequiredSize变量调用SetupDiGetDeviceInterfaceDetail。为了响应这样的调用,此函数返回RequiredSize的所需缓冲区大小,并失败,GetLastError返回错误“缓冲区不足”
2) 分配一个适当大小的缓冲区,并再次调用该函数以获取接口详细信息

如果您在下面查找“缓冲区不足”错误,您将看到它是十进制值122