驱动控制码计算小工具
本帖最后由 wushaominkk 于 2019-2-20 14:05 编辑学习驱动时,需要计算控制码,简单的写了一个,给需要的人。
代码:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
#define FILE_DEVICE_UNKNOWN 0x00000022
#define METHOD_BUFFERED 0
#define FILE_ANY_ACCESS 0
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
int _tmain(int argc, _TCHAR* argv[])
{
int nCalacCode;
int nFILE_READ_WRITE_ACCESS;
cout << "请输入需要计算的权限:\r\n0=FILE_ANY_ACCESS \r\n非0=FILE_READ_ACCESS + FILE_WRITE_ACCESS\r\n";
cin >> hex >> nCalacCode;
if (nCalacCode == 0)
{
nFILE_READ_WRITE_ACCESS = FILE_ANY_ACCESS;
}
else
{
nFILE_READ_WRITE_ACCESS = FILE_READ_ACCESS + FILE_WRITE_ACCESS;
}
cout << "请输入计数控制码:";
while (cin >> hex >> nCalacCode)
{
if (nCalacCode == 'q' || nCalacCode == 'Q')
{
break;
}
int nCtlCode = CTL_CODE(FILE_DEVICE_UNKNOWN, nCalacCode, METHOD_BUFFERED, nFILE_READ_WRITE_ACCESS);
printf("控制码:%08X\r\n", nCtlCode);
cout << "请输入计数控制码:";
}
return 0;
}
页:
[1]