DeviceIoControl的使用说明
应用程序和驱动程序的通信过程是:应用程序使用CreateFile函数打开设备,然后用DeviceIoControl与驱动程序进行通信,包含读和写两种操作。还能够用ReadFile读数据用WriteFile写数据。操作完成时用CloseHandle关闭设备。我们比較经常使用的就是用DeviceIoControl对设备进行读写操作。先看看DeviceIoControl是怎么定义的:
BOOL DeviceIoControl(
HANDLE hDevice,
DWORD dwIoControlCode,
LPVOID lpInBuffer,
DWORD nInBufferSize,
LPVOID lpOutBuffer,
DWORD nOutBufferSize,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped
);
Parameters(參数)
- hDevice (CreateFile返回的设备句柄)
- [in] Handle to the device that is to perform the operation. To obtain a device handle, call the CreateFile function.
- dwIoControlCode (应用程序调用驱动程序的控制命令,就是IOCTL_XXX IOCTLs )
- [in] IOCTL for the operation. This value identifies the specific operation to perform and the type of device on which to perform the operation. There are no specific values defined for the dwIoControlCode parameter. However, you can define custom IOCTL_XXX IOCTLs with the CTL_CODE macro. You can then advertise these IOCTLs and an application can use these IOCTLs with DeviceIoControl to perform the driver-specific functions.
- lpInBuffer (应用程序传递给驱动程序的数据缓冲区地址)
- [in] Long pointer to a buffer that contains the data required to perform the operation. Set to NULL if the dwIoControlCode parameter specifies an operation that does not require input data.
- nInBufferSize (应用程序传递给驱动程序的数据缓冲区大小,字节数)
- [in] Size, in bytes, of the buffer pointed to by lpInBuffer.
- lpOutBuffer (驱动程序返回给应用程序的数据缓冲区地址)
- [out] Long pointer to a buffer that receives the output data for the operation. Set to NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.
- nOutBufferSize (驱动程序返回给应用程序的数据缓冲区大小,字节数)
- [out] Size, in bytes, of the buffer pointed to by lpOutBuffer.
- lpBytesReturned (驱动程序实际返回给应用程序的数据字节数地址)
- [out] Long pointer to a variable that receives the size, in bytes, of the data stored in lpOutBuffer. The DeviceIoControl function may unnecessarily use this parameter. For example, if an operation does not produce data for lpOutBuffer and lpOutBuffer is NULL, the value of lpBytesReturned is meaningless.
- lpOverlapped (重叠操作结构)
- [in] Ignored; set to NULL.
Return Values(返回值)
Nonzero indicates success. Zero indicates failure. To obtain extended error information, call the GetLastError function. (非0成功,0失败)
详细使用我们看看列子:
1,向设备传递数据,我们定义一个函数来实现
bool CDeviceOperDlg::SendKeyData(HANDLE handle, BYTE *bData, int iSize)
{
ULONG nOutput;
BYTE bTemp[512];
//将数据放置到发送数组
memset(bTemp,0,sizeof(bTemp));
memcpy(bTemp,&bData[0],iSize);
//向设备发送
if (!DeviceIoControl(handle,
ATST2004_IOCTL_WRITE, //依据详细的设备有相关的定义
bTemp, //向设备传递的数据地址
iSize, //数据大小,字节数
NULL, //没有返回的数据,置为NULL
0, //没有返回的数据,置为0
&nOutput,
NULL)
)
{
return false;
}
return true;
}
2,从设备读取数据
bool CDeviceOperDlg::ReviceKeyData(HANDLE handle, BYTE *bData, int iSize)
{
ULONG nOutput;
BYTE bTemp[512];
//数组清零
memset(bTemp,0,sizeof(bTemp));
//向设备发送
if (!DeviceIoControl(handle,
ATST2004_IOCTL_READ, //依据详细的设备有相关的定义
NULL, //没有向设备传递的数据,置为NULL
0, //没有向设备传递的数据,置为NULL
bTemp, //读取设备的数据返回地址
iSize, //读取数据的字节数
&nOutput,
NULL)
)
{
return false;
}
//放置到公用数组
memcpy(&bData[0],&bTemp[0],iSize);
return true;
}
DeviceIoControl的使用说明的更多相关文章
- Atitit.项目修改补丁打包工具 使用说明
Atitit.项目修改补丁打包工具 使用说明 1.1. 打包工具已经在群里面.打包工具.bat1 1.2. 使用方法:放在项目主目录下,执行即可1 1.3. 打包工具的原理以及要打包的项目列表1 1. ...
- awk使用说明
原文地址:http://www.cnblogs.com/verrion/p/awk_usage.html Awk使用说明 运维必须掌握的三剑客工具:grep(文件内容过滤器),sed(数据流处理器), ...
- “我爱背单词”beta版发布与使用说明
我爱背单词BETA版本发布 第二轮迭代终于画上圆满句号,我们的“我爱背单词”beta版本已经发布. Beta版本说明 项目名称 我爱背单词 版本 Beta版 团队名称 北京航空航天大学计算机学院 拒 ...
- Oracle 中 union 和union all 的简单使用说明
1.刚刚工作不久,经常接触oracle,但是对oracle很多东西都不是很熟.今天我们来了解一下union和union all的简单使用说明.Union(union all): 指令的目的是将两个 S ...
- Map工具系列-02-数据迁移工具使用说明
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- Map工具系列-03-代码生成BySQl工具使用说明
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- gdbsever 使用说明
gdbsever 使用说明 在新塘N3292x平台下 编译 gdbsever ./configure --target=arm-linux --host=arm-linux arm-linux-gdb ...
- mongoVUE的增删改查操作使用说明
mongoVUE的增删改查操作使用说明 一. 查询 1. 精确查询 1)右键点击集合名,再左键点击Find 或者直接点击工具栏上的Find 2)查询界面,包括四个区域 {Find}区,查询条件格式{& ...
随机推荐
- Linux渗透+SSH内网转发
http://www.jb51.net/hack/58514.html http://blog.chinaunix.net/uid-756931-id-353243.html http://blog. ...
- winzip15.0许可证
username:Juzhaofeng 授权码:MPZRP-Y7LWW-K1DKG-FM92E-2C5F5-ZEKFF
- java.lang.OutOfMemoryError: Java heap space错误和方法(集、转)
错误的方式来解决溢出下面的堆空间是从网上找: java.lang.OutOfMemoryError: Java heap space ================================= ...
- 自己写shell命令pwd
思维:(1)得到"."的i节点号,叫n(使用stat) (2)chdir ..(使用chdir) (3)找到inode号为n的节点,得到其文件名称. 反复上述操作直到当前文件夹&q ...
- Eclipse+Maven命令创建webapp项目<三>
1.使用maven命令:mvn archetype:create -DgroupId=xxxxx -DartifactId=web-sample -DarchetypeArtifactId=maven ...
- Javascript设计模式系列一
定义类,方法赋值给prototype属性各种写法: 方法一: <script type="text/javascript"> ////定义Message类 var Me ...
- TRIZ系列-创新原理-22-变害为利原理
变害为利原理的详细表述例如以下:1)利用有害的因素(特别是环境中的)获得积极的效果: 有害无害不过相对的(时间,空间,人),将有害的因素通过一定的处理和转化,能够变有害为实用,比方废品回收, ...
- android 中国通信乱码问题
1.要解决中文乱码问题.首先得了解什么是字符编码 计算机要处理各种字符,就须要将字符和二进制内码相应起来,这样的相应关系就是字符编码. 要制定字符编码首先要确定字符集,并将 字符集内的字符排序.然后和 ...
- 阅读<反欺骗的艺术>思考
早期接受csdn发送本书<反欺骗的艺术 ---- 传说中的黑客世界里,分享经验>. 经过这本书发生床头, 每天晚上看上.直到今天, 刚读的书. 颇有感觉. 之所以当初选择读这本书, 完全被 ...
- android 他们定义对话框
创建一个布局文件 my_dialog.xml <?xml version="1.0" encoding="utf-8"?> <Relative ...