阅读:1233回复:2
请看看帮我《Windows 2000 设备驱动程序设计指南》中的例子
书中第7章有一个内核模式驱动的例子,我已经把他编译好了,并且安装好了,在计算机管理里面可以看到了,下面的例子是来测试这个驱动程序的,可是运行是老是提示驱动文件不能打开,请问是怎么回事?
#include <windows.h> #include <stdio.h> int main() { HANDLE hDevice; BOOL status; printf(\"Beginning test of Loopback Driver (CH7)...\\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\"); char outBuffer[] = \"This is a test of the Loopback device\"; DWORD outCount = sizeof(outBuffer); DWORD bW; status = WriteFile(hDevice, outBuffer, outCount, &bW, NULL); if (!status) { printf(\"Failed on call to WriteFile - error: %d\\n\", GetLastError() ); return 2; } if (outCount == bW) { printf(\"Succeeded in writing %d bytes\\n\", outCount); printf(\"Buffer was: %s\\n\", outBuffer); } else { printf(\"Failed to write the correct number of bytes.\\n\" \"Attempted to write %d bytes, but WriteFile reported %d bytes.\\n\", outCount, bW); return 3; } printf(\"Attempting to read from device...\\n\"); char inBuffer[80]; DWORD inCount = sizeof(inBuffer); DWORD bR; status = ReadFile(hDevice, inBuffer, inCount, &bR, NULL); if (!status) { printf(\"Failed on call to ReadFile - error: %d\\n\", GetLastError() ); return 4; } if (bR == bW) { printf(\"Succeeded in reading %d bytes\\n\", bR); printf(\"Buffer was: %s\\n\", inBuffer); } else { printf(\"Failed to read the correct number of bytes.\\n\" \"Should have read %d bytes, but ReadFile reported %d bytes.\\n\", bW, inCount); 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; } 驱动程序的名字为loopback.sys,我把CreateFile函数中的LBK1改为loopback也不管用,请问怎么回事? |
|
沙发#
发布于:2002-06-07 09:50
看看你驱动中的创建的符号名是什么,然后再用这个符号名去打开它。
|
|
|
板凳#
发布于:2002-06-08 22:42
这个例子我用过,按照书上的步骤能接上至于你的原因,问题还不太明白请说明白点,
顺便问你一下,为何第九章开始的例子编译无法通过提示,“WDN。h\" 无法打开,但各种设置和前面例子一样,前面的却可以,为何 |
|