很简单,如果想不用别人的工具,可以参照下面的代码
===============================
/*
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\MEM]
"Dll"="MyMemoryDrv.dll"
"Prefix"="MEM"
"Index"=dword:1
"Order"=dword:0
"FriendlyName"="MEM driver"
*/
#define MEM_DRV_NAME L"MEM1:"
bool LoadMemDrv(void)
{
BOOL bRetVal = false;
// Step1: modify the registry
class CReg MemDrvReg;
bRetVal = MemDrvReg.Create(HKEY_LOCAL_MACHINE, MEM_DRV_PATH);
bRetVal= MemDrvReg.SetSZ(L"Dll", L"MyMemoryDrv.dll");//, sizeof(L"MyMemoryDrv.dll")/sizeof(TCHAR));
MemDrvReg.SetSZ(L"Prefix", L"MEM");//, sizeof(L"MEM")/sizeof(TCHAR));
MemDrvReg.SetDW(L"Order", 0);
MemDrvReg.SetDW(L"Index", 1);
MemDrvReg.SetDW(L"Index", 1);
MemDrvReg.SetSZ(L"FriendlyName", L"MEM driver");//, sizeof(L"MEM driver")/sizeof(TCHAR));
// Step2: load driver unsing device manager
hActiveMemDrv = INVALID_HANDLE_VALUE;
hActiveMemDrv = ActivateDevice(MEM_DRV_PATH, 0);
if (INVALID_HANDLE_VALUE == hActiveMemDrv)
{
LogMessage(L"[ERR]Load driver %s failed", MEM_DRV_FULL_PATH);
goto EXIT;
}
// Step3: Open stream driver
hFile = INVALID_HANDLE_VALUE;
hFile = CreateFile(MEM_DRV_NAME,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
LogMessage(L"[ERR] Open stream driver %s failed. Error code 0x%8x", MEM_DRV_NAME, GetLastError());
goto EXIT;
}
bIsDrvLoad = true;
bRetVal = TRUE;
EXIT:
return (bRetVal == TRUE);
}
或者http://blog.eeworld.net/guopeixin/archive/2009/12/01/4917210.aspx
|