📄 testor.cpp
字号:
// Testor for Chapter 11 Timer-based Parallel Port Driver
#include <windows.h>
#include <stdio.h>
int main() {
HANDLE hDevice;
BOOL status;
printf("Beginning test of Extensive Parallel Port Driver...\n");
hDevice =
CreateFile("\\\\.\\LBK1",
GENERIC_READ | GENERIC_WRITE,
0, // share mode none
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL ); // no template
if (hDevice == INVALID_HANDLE_VALUE) {
printf("Failed to obtain file handle to device: "
"%s with Win32 error code: %d\n",
"LBK1", GetLastError() );
return 1;
}
printf("Succeeded in obtaining handle to LBK1 device.\n");
printf("Attempting write to device...\n");
ULONG ioBuffer[43] = { 1L, 4L, 1L};
DWORD ioCount = sizeof(ioBuffer);
DWORD bW, bR;
status =
WriteFile(hDevice, ioBuffer, ioCount, &bW, NULL);
if (!status) {
printf("Failed on call to WriteFile - error: %d\n",
GetLastError() );
return 2;
}
if (ioCount == bW) {
printf("Succeeded in writing %d bytes\n", ioCount);
printf("Buffer for out was: \n");
for (DWORD i=0; i<bW/sizeof(ULONG); i++)
printf("%08X ", ioBuffer[i]);
printf("\n");
} else {
printf("Failed to write the correct number of bytes.\n"
"Attempted to write %d bytes, but WriteFile reported %d bytes.\n",
ioCount, bW);
return 3;
}
printf("Attempting to read from device...\n");
status =
ReadFile(hDevice, ioBuffer, ioCount, &bR, NULL);
if (!status) {
printf("Failed on call to ReadFile - error: %d\n",
GetLastError() );
return 4;
}
if (ioCount == bR) {
printf("Succeeded in reading %d bytes\n", bR);
printf("Buffer for in was: \n");
for (DWORD i=0; i< bR/sizeof(ULONG); i++)
printf("%08X ", ioBuffer[i]);
printf("\n");
} else {
printf("Failed to read the correct number of bytes.\n"
"Should have read %d bytes, but ReadFile reported %d bytes.\n",
bW, ioCount);
return 5;
}
printf("Attempting to close device LBK1...\n");
status =
CloseHandle(hDevice);
if (!status) {
printf("Failed on call to CloseHandle - error: %d\n",
GetLastError() );
return 6;
}
printf("Succeeded in closing device...exiting normally\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -