应用层与驱动层交互
#include <iostream>
#include<Windows.h>
int main()
{
DWORD td = 0;
CHAR readBuffer[50] = { 0 };
HANDLE hDevice = CreateFile(TEXT("\\\\.\\MyfirstDevice"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Create hdevice is failed!~");
system("pause");
return 0;
}
printf("open successful!\n");
system("pause");
ReadFile(hDevice, (PVOID)readBuffer, 50, &td, NULL);
printf("%p---%s---%d", readBuffer, readBuffer, td);
system("pause");
WriteFile(hDevice, "This is from R3.", strlen("This is from R3."), &td, NULL);
CloseHandle(hDevice);
system("pause");
return 0;
}