Exemplo n.º 1
0
        private static string GetDevicePath(IntPtr deviceInfoSet, NativeMethods.SpDeviceInterfaceData deviceInterfaceData)
        {
            var bufferSize      = 0;
            var interfaceDetail = new NativeMethods.SpDeviceInterfaceDetailData {
                Size = IntPtr.Size == 4 ? 4 + Marshal.SystemDefaultCharSize : 8
            };

            NativeMethods.SetupDiGetDeviceInterfaceDetailBuffer(deviceInfoSet, ref deviceInterfaceData, IntPtr.Zero, 0, ref bufferSize, IntPtr.Zero);

            return(NativeMethods.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref deviceInterfaceData, ref interfaceDetail, bufferSize, ref bufferSize, IntPtr.Zero) ? interfaceDetail.DevicePath : null);
        }
Exemplo n.º 2
0
        private static string GetDevicePath(
            IntPtr deviceInfoSet, NativeMethods.SpDeviceInterfaceData deviceInterfaceData)
        {
            var bufferSize = 0;
            var interfaceDetail = new NativeMethods.SpDeviceInterfaceDetailData {
                                                                                        Size =
                                                                                            IntPtr.Size == 4
                                                                                                ? 4 +
                                                                                                  Marshal
                                                                                                      .SystemDefaultCharSize
                                                                                                : 8
                                                                                    };

            NativeMethods.SetupDiGetDeviceInterfaceDetailBuffer(
                                                                deviceInfoSet, ref deviceInterfaceData, IntPtr.Zero, 0,
                                                                ref bufferSize, IntPtr.Zero);

            return NativeMethods.SetupDiGetDeviceInterfaceDetail(
                                                                 deviceInfoSet, ref deviceInterfaceData,
                                                                 ref interfaceDetail, bufferSize, ref bufferSize,
                                                                 IntPtr.Zero) ? interfaceDetail.DevicePath : null;
        }