这段代码实在看不懂了。请指点一下。谢谢!
using System;
using System.Runtime.InteropServices;
using System.Text;namespace UsbEject.Library
{
internal sealed class Native
{
      
        internal const int WM_DEVICECHANGE = 0x0219;
internal const int INVALID_HANDLE_VALUE = -1;
        internal const int GENERIC_READ = unchecked((int)0x80000000);
        internal const int FILE_SHARE_READ = 0x00000001;
        internal const int FILE_SHARE_WRITE = 0x00000002;
        internal const int OPEN_EXISTING = 3;        [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
        internal static extern bool GetVolumeNameForVolumeMountPoint(
            string volumeName,
            StringBuilder uniqueVolumeName,
            int uniqueNameBufferCapacity);        [DllImport("Kernel32.dll", SetLastError = true)]
        internal static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);        [DllImport("Kernel32.dll", SetLastError = true)]
        internal static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize, IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned, IntPtr lpOverlapped);        [DllImport("Kernel32.dll", SetLastError = true)]
        internal static extern bool CloseHandle(IntPtr hObject);
internal const int ERROR_NO_MORE_ITEMS = 259;
internal const int ERROR_INSUFFICIENT_BUFFER = 122;
internal const int ERROR_INVALID_DATA = 13;
internal const string GUID_DEVINTERFACE_VOLUME = "53f5630d-b6bf-11d0-94f2-00a0c91efb8b";
internal const string GUID_DEVINTERFACE_DISK = "53f56307-b6bf-11d0-94f2-00a0c91efb8b";
        internal const int IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS = 0x00560000;
       
        [StructLayout(LayoutKind.Sequential)]
internal struct DISK_EXTENT 
{
internal int DiskNumber;
internal long StartingOffset;
internal long ExtentLength;
}

解决方案 »

  1.   

    特别是以下几段:
    [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern bool GetVolumeNameForVolumeMountPoint(
                string volumeName,
                StringBuilder uniqueVolumeName,
                int uniqueNameBufferCapacity);        [DllImport("Kernel32.dll", SetLastError = true)]
            internal static extern IntPtr CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);        [DllImport("Kernel32.dll", SetLastError = true)]
            internal static extern bool DeviceIoControl(IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize, IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned, IntPtr lpOverlapped);        [DllImport("Kernel32.dll", SetLastError = true)]
            internal static extern bool CloseHandle(IntPtr hObject);