我按照书上的例子创建了一个VS2005的基于WM6 SDK的Win32 DLL工程,然后输入源代码,如下
#include
#include
#define MAX_LENGTH 1024
HANDLE ghFile = NULL;
BOOL WINAPI DllEntryPoint(HANDLE hinstDLL, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
DWORD LOG_Init(DWORD dwContext)
{
ghFile = NULL;
return 1;
}
DWORD LOG_Deinit(DWORD dwContext)
{
ghFile = NULL;
return 1;
}
DWORD LOG_Open(DWORD hDeviceContext, DWORD dwAccessCode, DWORD dwShareMode)
{
ghFile = ::CreateFile(L"\\driver_log.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
return (ghFile != INVALID_HANDLE_VALUE);
}
DWORD LOG_Close(DWORD hOpenContext)
{
if (ghFile != NULL && ghFile != INVALID_HANDLE_VALUE)
{
::CloseHandle(ghFile);
ghFile = NULL;
return TRUE;
}
return FALSE;
}
BOOL LOG_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActualOut)
{
return TRUE;
}
void LOG_PowerDown(DWORD hDeviceContext)
{
}
void LOG_PowerUp(DWORD hDeviceContext)
{
}
DWORD LOG_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD dwCount)
{
DWORD dwActualCount = 0;
if (::ReadFile(ghFile, pBuffer, dwCount, &dwActualCount, NULL))
{
return dwActualCount;
}
return 0;
}
DWORD LOG_Seek(DWORD hOpenContext, long lAmount, DWORD dwType)
{
return 0;
}
DWORD LOG_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD dwCount)
{
DWORD dwActualCount = 0;
if (::WriteFile(ghFile, pBuffer, dwCount, &dwActualCount, NULL))
{
return dwActualCount;
}
return 0;
}
然后创建一个def文件如下
LIBRARY"DriverLog"
EXPORTS
LOG_Init
LOG_Deinit
LOG_Open
LOG_Close
LOG_IOControl
LOG_PowerDown
LOG_PowerUp
LOG_Read
LOG_Seek
LOG_Write
编译成功之后,不知道如何部署并注册到 Windows Mobile 6 的模拟器上,所以就手动用 ActiveSync 把 DriverLog.dll 文件 copy 到模拟器的 \windows 目录下,然后手动在WM6模拟器上输入如下注册表值(通过 Remote Registry Editor)
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\DriverLog]
"Index" = dword:1
"Prefix" = "LOG"
"Dll" = "DriverLog.dll"
Order = dword:0
软重起模拟器
我的意图是创建一个虚拟的驱动程序,然后可以往 LOG1 端口里写入或者读取东西,可是为什么我的测试程序能够打开端口并写入,但是却读不出来,好像我的那个驱动根本就没有起作用?创建一个流接口的驱动程序的步骤到底应该怎么样?