首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#怎么使用CreateFile和DeviceIoControl

2013-04-07 
c#如何使用CreateFile和DeviceIoControl想先打开一个sys,然后与其通信。用C++使用这2个函数。但是c#该如何使

c#如何使用CreateFile和DeviceIoControl
想先打开一个sys,然后与其通信。
用C++使用这2个函数。但是c#该如何使用呢?
[解决办法]


[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;

要声明出来。
[解决办法]
C#,可能还包括所有.net语言,都不能访问形如@"\\.\"的设备文件,也就是说.net不能直接访问设备文件。我试过。你要想访问设备文件只能自己用C++之类的语言做个native DLL,然后.net通过这个DLL访问设备文件。

热点排行