//在注册表中查找写入链表

std::map<CString,CString> GetSerPort()
{
std::map<CString,CString> resMap;
HKEY hKey;
char arCom[20] = {-1};
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey)==ERROR_SUCCESS){
char szPortName[256], szComName[32];
DWORD dwLong, dwSize;
int nCount =0;
while(true){
dwLong = 256;
dwSize = 256;
if(RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize)==ERROR_NO_MORE_ITEMS){
break;
}
nCount++;

resMap.insert(make_pair(CString(szPortName),CString(szComName)));
}
RegCloseKey(hKey);
}
return resMap;
}

 

//迭代读取

std::map<CString,CString> portMap = m_prOper.GetSerPort();

std::map<CString,CString>::iterator itor;

for(itor = portMap.begin();itor != portMap.end();itor++)
{
  m_com.InsertString(indexPr,itor->second);
  m_com.SetItemData(indexPr++,atoi(itor->second.Mid(3)));

}

 

posted on 2018-03-16 09:47  ~纸鸢~  阅读(99)  评论(0)    收藏  举报