- 注册时间
- 2021-4-16
- 最后登录
- 2024-7-7
- 在线时间
- 4 小时
编程入门
- 龙马币
- 52
|
C/C++ 驱动取任意物理地址源码
应用层代码:
- //R3
- #include <stdio.h>
- #include <windows.h>
- #define _SYB_NAME L"\\\\.\\sysmblicname"
- #define CTL_CODE_BASE 0x8000
- #define CTL_ALLCODE(i) CTL_CODE(FILE_DEVICE_UNKNOWN,CTL_CODE_BASE+i,METHOD_BUFFERED,FILE_ANY_ACCESS)
- #define CTL_TALK CTL_ALLCODE(1)
- int main()
- {
- HANDLE hDevice = CreateFile(_SYB_NAME, FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (!hDevice)
- {
- printf("%x", GetLastError());
- }
- else
- {
- do
- {
- char inbuf[260] = { 0 };
- char outbuf[260] = { 0 };
- DWORD retlen = 0;
- printf("创建成功\n");
- printf("input:");
- scanf_s("%d", outbuf);
- int flag = DeviceIoControl(hDevice, CTL_TALK, outbuf, sizeof(outbuf), inbuf, 1, &retlen, NULL);
- if (!flag)
- {
- printf("控制码通信失败");
- printf("%d\n", GetLastError());
- getchar();
- }
- } while (1);
- }
- getchar();
- }
复制代码
驱动代码:
|
|