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}区,查询条件格式{& ...
随机推荐
- php 禁止 URL 直接访问 php文件
通过判断访问来源来实现. $fromurl="http://www.111.com/index.php"; //只能从这个地址访问 if( $_SERVER['HTTP_REFER ...
- android一些面试题目
1.ListView怎么提高滑动效率 2.说下你做过项目的包的构架,(联网,解析,activity,database) 重点 3.载入大量图片怎么做(包含小图和查看大图) 怎么降低一次跟server的 ...
- SQL Server :理解GAM和SGAM页
原文:SQL Server :理解GAM和SGAM页 我们知道SQL Server在8K 的页里存储数据.分区就是物理上连续的8个页.当我们创建一个数据库,数据文件会被逻辑分为页和区,当用户对象创建时 ...
- windows phone (27) 基础Button
原文:windows phone (27) 基础Button Button 在wp7中因其灵活性经常会用到,我们在ContentPanel中直接添加Button,button默认状态下是把整个grid ...
- easyui出口excel无法下载框弹出的办法来解决
使用前ajax发,码如下面(ActionUrl一般处理程序ashx路径): $.ajax({ url: ActionUrl + '?action=export&ID=' + $('#fm_ID ...
- C++程序代写实现HashSet class
C++程序代写实现HashSet class 专业程序代写(QQ:928900200) Implement a HashSet class for elements of type string.It ...
- android手机SD卡中的android_secure目录
.android_secure 是官方app2sd的产物,删了之后装到sd卡中的软件就无法使用了.里面有非常多.asec的文件,都是装到SD卡上的软件,可是一般装到sd卡中的程序被卸载了.androi ...
- 怎么样putty打开图形化管理工具,在终端上
有时需要在putty这种图形终端开放的图形化管理工具将出现以下错误: [root@node2 ~]# Traceback (most recent call last): File "/us ...
- .NET API for RabbitMQ and ActiveMQ
EasyNetQ: .NET API for RabbitMQ: https://github.com/mikehadlow/EasyNetQ/wiki/Quick-Start Or: http:// ...
- String和StringBuffer 常用方法总结
String和StringBuffer 常用方法总结 一.不可变长度String 1.字符串---->char数组 char[] chars=str.toCharArray(); 2.字符串中 ...