HKEY hKey;
LONG ret;
OSVERSIONINFO osvi;
BOOL bOsVersionInfoEx;
char keyinfo[100],comm_name[200],ValueName[200], Uart[16];
int i;
DWORD sType,Reserved,cbData,cbValueName;

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

memset(keyinfo,0,100);
strcpy(keyinfo,"HARDWARE\\DEVICEMAP\\SERIALCOMM");
i=0; sType=REG_SZ;Reserved=0;
bOsVersionInfoEx =GetVersionEx(&osvi);
ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyinfo,0,KEY_ALL_ACCESS,&hKey);
if (ret==ERROR_SUCCESS){
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
for(i=1;i<=128;i++)
{
sprintf(comm_name,"COM%d",i);
m_Uart.AddString(comm_name);
}
}
else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
do
{
cbData=200;cbValueName=200;
memset(comm_name,0,200);
memset(ValueName,0,200);
ret=RegEnumValue(hKey,i,ValueName,&cbValueName,NULL,&sType,(LPBYTE)comm_name,&cbData);
if (strlen(comm_name) > 0)
{
// 检测出来的串口
}
i++;
}while (ret==ERROR_SUCCESS);
}
}

RegCloseKey(hKey);

相关文章:

  • 2022-03-06
  • 2022-02-07
  • 2022-12-23
  • 2021-11-21
  • 2021-11-12
  • 2021-09-09
  • 2021-07-04
  • 2021-08-05
猜你喜欢
  • 2022-01-26
  • 2022-12-23
  • 2021-05-21
  • 2021-04-04
  • 2021-07-29
  • 2021-09-16
  • 2021-06-20
相关资源
相似解决方案