本帖最后由 bjfscasm 于 2010-05-29 16:58:00 编辑

解决方案 »

  1.   


    SHORT RWCenter::GetAllComm(){
    HKEY hKey;
    LONG ret;
    SHORT retVal = 0;
    OSVERSIONINFO  osvi;
    BOOL bOsVersionInfoEx; TCHAR keyinfo[100],comm_name[200],ValueName[200];
    int i;
    DWORD sType,Reserved,cbData,cbValueName; ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); memset(keyinfo,0,100*sizeof(TCHAR));
    _tcscpy_s(keyinfo,_T("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_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 (ret==ERROR_SUCCESS)
    {
     //m_list.Add(comm_name);
     int temp;
     temp = _tstoi(&comm_name[3]);
     retVal |= 1 << (temp -1);
     i++;
    }
    }while (ret==ERROR_SUCCESS);
    }
    } //CString strPortName = GetSetComName();
    //m_ctrlPort.SetWindowText(strPortName);
    RegCloseKey(hKey);

    return retVal;
    }