Readfile与Createfile,该怎么解决
Readfile与Createfile
我想问一下readfile与createfile是否可以操作键盘和鼠标?如果不能那还有什么函数可以呢?就是USB键盘和鼠标。
------解决方案--------------------
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);//键盘消息
VOID mouse_event(
DWORD dwFlags, // motion and click options
DWORD dx, // horizontal position or change
DWORD dy, // vertical position or change
DWORD dwData, // wheel movement
ULONG_PTR dwExtraInfo // application-defined information
);鼠标消息
------解决方案--------------------
应该可以吧,还有的函数就是DeviceIoControl了
------解决方案--------------------
http://topic.****.net/t/20020826/15/971063.html
------解决方案--------------------
DeviceIoControl也是应用层跟驱动层数据交互的方法之一
------解决方案--------------------
CreateFile失败,你看看GetLastError函数的返回值是什么?
------解决方案--------------------
我想问一下readfile与createfile是否可以操作键盘和鼠标?如果不能那还有什么函数可以呢?就是USB键盘和鼠标。
------解决方案--------------------
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);//键盘消息
VOID mouse_event(
DWORD dwFlags, // motion and click options
DWORD dx, // horizontal position or change
DWORD dy, // vertical position or change
DWORD dwData, // wheel movement
ULONG_PTR dwExtraInfo // application-defined information
);鼠标消息
------解决方案--------------------
应该可以吧,还有的函数就是DeviceIoControl了
------解决方案--------------------
http://topic.****.net/t/20020826/15/971063.html
------解决方案--------------------
DeviceIoControl也是应用层跟驱动层数据交互的方法之一
------解决方案--------------------
CreateFile失败,你看看GetLastError函数的返回值是什么?
------解决方案--------------------
- C/C++ code
/*HANDLE hDevice = ::CreateFile("\\\\.\\MyDevice", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hDevice == INVALID_HANDLE_VALUE) { cout << ::GetLastError() << endl; cout << "打开失败!" << endl; return 0; } char buf[10]; memset(buf, 0, 10); DWORD nReaded = 0; ::ReadFile(hDevice, buf, 9, &nReaded, NULL); for (int i = 0; i < 10; i++) { printf("%x", buf[i]); }
------解决方案--------------------
没看出你写的哪有问题,这是我很久以前写的,访问驱动的,肯定是可以的。
------解决方案--------------------
//本设备只能以写的方式创建。取得设备的句柄
hDevice = CreateFile(strtDetailData->DevicePath,
GENERIC_WRITE|GENERIC_READ,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
权限不足,参数里的读写访问权限降低看看效果