 
- UID
- 1029342
- 性别
- 男
|

Parameters
lpszDevKey
[in] Pointer to a string containing the registry path of the device driver's registry key. This key contains the driver's DLL name, prefix, and other data. For information about the subkeys of the HKEY_LOCAL_MACHINE/Drivers/Active registry key, see Device Manager Registry Keys.
lpRegEnts
[in] Pointer to an array of REGINI structures, each of which defines a registry value to add to the device's Active registry key before its driver is loaded. Set to NULL unless it is for a bus driver.
cRegEnts
[in] Count of the number of REGINI structures to which lpRegEnts points. This affects a generalization of the ActivateDevice function.
lpvParam
[in] Opaque pointer to a driver-specific data structure. You can use it to pass parameters to the loaded driver without having to write them through the registry. lpvParam is passed to the XXX_Init (Device Manager) function as a second parameter. lpvParam can be used by bus drivers to pass bus-specific information, entry points, or both to loaded drivers. Using this parameter prevents clients of that bus from becoming bus-agnostic. This is acceptable for some busses, especially those whose drivers cannot become bus-agnostic.
Return Values
Returns a handle that you can use later as the parameter to the DeactivateDevice function, if successful. If the function is not successful, it returns INVALID_HANDLE_VALUE. To obtain extended error information, call GetLastError.
4.调用函数DeactivateDevice来卸载CMC驱动。
DeactivateDevice函数
BOOL DeactivateDevice(
HANDLE hDevice
);
Parameters
hDevice
[in] Handle to an active device. The ActivateDevice and ActivateDeviceEx functions return this value.
Return Values
Nonzero indicates success. Zero indicates failure.
5.本文是基于对话框的方式来实现的,加载和卸载的对话框对应的函数如下
加载CMC.dll的函数
void CloaddriverDlg::OnBnClickedLoadDriver()
{
LONG lResult = 0;
DWORD dwParam = 88;
HKEY hOpenKey;
DWORD OpenStyle;
DWORD ErrorCode=0;
CString strTmp;
TCHAR CmcRootKey[] = TEXT("Drivers//BuiltIn//CMC");
TCHAR OrderKeyName[] = TEXT("Order");
DWORD OrderKeyValue = 0;
TCHAR InderKeyName[] = TEXT("Inder");
DWORD InderKeyValue = 1;
TCHAR PrefixKeyName[] = TEXT("Prefix");
TCHAR PrefixKeyValue[] = TEXT("CMC");
TCHAR DllKeyName[] = TEXT("Dll");
TCHAR DllKeyValue[] = TEXT("CMC.dll");
lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,CmcRootKey,0,L"",0,0,NULL,&hOpenKey,&OpenStyle);
if(ERROR_SUCCESS == lResult)
{
RegSetValueEx(hOpenKey,OrderKeyName,0,REG_DWORD,(BYTE *)&OrderKeyValue,sizeof(DWORD));
RegSetValueEx(hOpenKey,InderKeyName,0,REG_DWORD,(BYTE *)&InderKeyValue,sizeof(DWORD));
RegSetValueEx(hOpenKey,PrefixKeyName,0,REG_SZ,(BYTE *)PrefixKeyValue,sizeof(PrefixKeyValue));
RegSetValueEx(hOpenKey,DllKeyName,0,REG_SZ,(BYTE *)DllKeyValue,sizeof(DllKeyValue));
m_handle = ActivateDeviceEx(CmcRootKey,NULL,0,&dwParam);
ErrorCode = GetLastError();
strTmp.Format(_T("%x"),&ErrorCode);
CEdit *pDispEdit=(CEdit *)GetDlgItem(IDC_EDIT1);
pDispEdit->SetWindowText(strTmp);
UpdateData(FALSE);
if(m_handle == NULL)
{
MessageBox(_T("avtivate driver fail!"));
}
else
{
MessageBox(_T("avtivate driver success!"));
}
} |
|