[DllImport("kernel32.dll", EntryPoint="CreateFile")] public static extern int CreateFile ( string lpFileName, int dwDesiredAccess, int dwShareMode, ref SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile ); [DllImport("kernel32.dll", EntryPoint="DeviceIoControl")] public static extern int DeviceIoControl ( int hDevice, int dwIoControlCode, ref int lpInBuffer, int nInBufferSize, ref int lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, ref OVERLAPPED lpOverlapped );
public const int GENERIC_ALL = 0x10000000; public const int GENERIC_EXECUTE = 0x20000000; public const int GENERIC_READ = 0x80000000; public const int GENERIC_WRITE = 0x40000000;要声明出来。
[DllImport("kernel32.dll", EntryPoint="CreateFile")]
public static extern int CreateFile (
string lpFileName,
int dwDesiredAccess,
int dwShareMode,
ref SECURITY_ATTRIBUTES lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile
);
[DllImport("kernel32.dll", EntryPoint="DeviceIoControl")]
public static extern int DeviceIoControl (
int hDevice,
int dwIoControlCode,
ref int lpInBuffer,
int nInBufferSize,
ref int lpOutBuffer,
int nOutBufferSize,
ref int lpBytesReturned,
ref OVERLAPPED lpOverlapped
);
public const int GENERIC_EXECUTE = 0x20000000;
public const int GENERIC_READ = 0x80000000;
public const int GENERIC_WRITE = 0x40000000;要声明出来。
瞎说,误导楼主。C#调用windows api,DllImport "kernel32.dll" 直接可以访问设备!