19,502
社区成员
发帖
与我相关
我的任务
分享
BOOL CCameratestDlg::FineCISDevice()
{
HKEY hKey_tmp = NULL;
HKEY hKey = NULL;
TCHAR comNum[10];
TCHAR achKey[10];
CString comname,sActive,temp;
DWORD i = 0;
DWORD cbMaxSubKey = 10; //键名的长度
DWORD dwType = 10;
DWORD dwSize = 10;
sActive = _T("Drivers\\Active\\"); //注册表下已加载设备项
RegOpenKeyEx(HKEY_LOCAL_MACHINE,sActive,0,0,&hKey); //打开指定的键并把句柄复制给hKey
temp.Format(_T("%d"),i); //提示输出
AfxMessageBox(temp); //提示输出
AfxMessageBox(_T("开始读取子键值!"));
//列举HKEY_LOCAL_MACHINE\Drivers\Active下的子键XX并赋值给achKey
while (RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS/*ERROR_SUCCESS*/)
{
temp.Format(_T("%d"),i); //提示输出
AfxMessageBox(temp); //提示输出
//打开Drivers\Active\XX子键并赋值给hKey_tmp
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, sActive+achKey, 0, 0, &hKey_tmp) == ERROR_SUCCESS)
{ //读取指定键的的name值
if(RegQueryValueEx(hKey_tmp, _T("name"), NULL, &dwType, (BYTE *)&comNum, &dwSize) == ERROR_SUCCESS)
{
comname.Format(L"%s",comNum);
AfxMessageBox(comname); //提示输出
if(comname.Left(3) == L"CIS")
{
temp.Format(_T("%d"),i);
AfxMessageBox(temp);
AfxMessageBox(_T("摄像头驱动已加载!"));
RegCloseKey(hKey_tmp);
RegCloseKey(hKey);
return TRUE;
}
}
RegCloseKey(hKey_tmp);
}
ZeroMemory(achKey,10);
cbMaxSubKey = 10;
i++;
}
RegCloseKey(hKey);
temp.Format(_T("%d"),i);
AfxMessageBox(temp);
AfxMessageBox(_T("摄像头驱动没有加载!"));
return FALSE;
}