示例#1
0
QString KviIconManager::getSmallIconResourceName(SmallIcon eIcon)
{
	QString szName("smallicons:kcs_");
	szName.append(g_szIconNames[eIcon]);
	szName.append(".png");
	return szName;
}
示例#2
0
void SVResString::loadAddSVSEStrings(MAPNODE &objNode)
{
    string szName(""), szNameHelp(""), szNameTip(""), szMainTitle(""),
            szTitle(""), szEditTitle(""), szHost(""), szHostHelp(""),
            szHostTip(""), szAdvTitle(""), szDescription(""), szDescriptionHelp("");

    FindNodeValue(objNode, "IDS_SE_Label",          szName);
    FindNodeValue(objNode, "IDS_SE_Label_Tip",      szNameHelp);
    FindNodeValue(objNode, "IDS_SE_Label_Error",    szNameTip);
    FindNodeValue(objNode, "IDS_Basic_Option",      szMainTitle);
    FindNodeValue(objNode, "IDS_Add_SE_Title",      szTitle);
    FindNodeValue(objNode, "IDS_Edit_SE_Title",     szEditTitle);
    FindNodeValue(objNode, "IDS_Host_Name",         szHost);
    FindNodeValue(objNode, "IDS_Host_Name_Tip",     szHostHelp);
    FindNodeValue(objNode, "IDS_Host_Name_Error",   szHostTip);
    FindNodeValue(objNode, "IDS_Advance_Option",    szAdvTitle);
    FindNodeValue(objNode, "IDS_Description",       szDescription);
    FindNodeValue(objNode, "IDS_Desc_Help",         szDescriptionHelp);

    m_lsResource["IDS_SE_Label"] = szName;
    m_lsResource["IDS_SE_Label_Tip"] = szNameHelp;
    m_lsResource["IDS_SE_Label_Error"] = szNameTip;
    m_lsResource["IDS_Basic_Option"] = szMainTitle;
    m_lsResource["IDS_Add_SE_Title"] = szTitle;
    m_lsResource["IDS_Edit_SE_Title"] = szEditTitle;
    m_lsResource["IDS_Host_Name"] = szHost;
    m_lsResource["IDS_Host_Name_Tip"] = szHostHelp;
    m_lsResource["IDS_Host_Name_Error"] = szHostTip;
    m_lsResource["IDS_Advance_Option"] = szAdvTitle;
    m_lsResource["IDS_Description"] = szDescription;
    m_lsResource["IDS_Desc_Help"] = szDescriptionHelp;
}
示例#3
0
STDMETHODIMP CZ80Assembler::AddDefine(BSTR bstrName, VARIANT varValue)
{
	if (V_VT(&varValue) == VT_EMPTY || V_VT(&varValue) == VT_ERROR)
	{
		V_VT(&varValue) = VT_UI4;
		V_UI4(&varValue) = 1;
	}

	VARIANT varDefine;
	VariantInit(&varDefine);
	V_VT(&varDefine) = VT_BSTR;
	V_BSTR(&varDefine) = SysAllocString(L"");
	HRESULT hr = VariantChangeType(&varDefine, &varValue, 0, VT_BSTR);
	if (FAILED(hr))
	{
		return hr;
	}

	CW2A szName(bstrName);

	bool fRedefined = false;
	define_t *define = add_define(strdup(szName), &fRedefined);

	if (define != NULL)
	{
		CW2A szContents(V_BSTR(&varDefine));
		define->contents = strdup(szContents);
		return S_OK;
	}
	else
	{
		return E_FAIL;
	}
}
示例#4
0
void CSVSortList::enumGroup(string &szGroupIndex)
{
    list<string> lsGroupID;
    list<string>::iterator lsItem;
    OBJECT objGroup;

    base_param group;

    if(IsSVSEID(szGroupIndex))
    {
        objGroup = GetSVSE(szGroupIndex, m_szIDCUser, m_szIDCPwd);
        if(objGroup != INVALID_VALUE)
        {
            GetSubGroupsIDBySE(objGroup, lsGroupID);
            CloseSVSE(objGroup);
        }
    }
    else
    {
        objGroup = GetGroup(szGroupIndex, m_szIDCUser, m_szIDCPwd);
        if(objGroup != INVALID_VALUE)
        {
            GetSubGroupsIDByGroup(objGroup, lsGroupID);
            CloseGroup(objGroup);
        }
    }

    int nIndex = 0;
    for(lsItem = lsGroupID.begin(); lsItem != lsGroupID.end(); lsItem ++)
    {
        string szID = (*lsItem).c_str();
        bool bHasRight = true;
        if(m_pSVUser)
            bHasRight = m_pSVUser->haveGroupRight(szID, Tree_DEVICE);
        if(bHasRight)
        {
            objGroup = GetGroup(szID, m_szIDCUser, m_szIDCPwd);
            if(objGroup != INVALID_VALUE)
            {
                MAPNODE node = GetGroupMainAttribNode(objGroup);
                if(node != INVALID_VALUE)
                {
                    string szName (""), szIndex ("");
                    FindNodeValue(node, "sv_name", szName);
                    FindNodeValue(node, "sv_index", szIndex);
                    if(szIndex.empty())
                        nIndex = FindIndexByID(szID);
                    else
                        nIndex = atoi(szIndex.c_str());
                    group.szIndex = szID;
                    group.szName = szName;
                    m_sortList[nIndex] = group;
                }
                CloseGroup(objGroup);
            }
        }
    }
}
示例#5
0
void CSVSortList::enumMonitor(string &szDeviceIndex)
{
    OBJECT objDevice = GetEntity(szDeviceIndex,  m_szIDCUser, m_szIDCPwd);
    if(objDevice != INVALID_VALUE)
    {
        list<string> lsMonitorID;
        list<string>::iterator lstItem;
        if (GetSubMonitorsIDByEntity(objDevice, lsMonitorID))
        {
            string szDeviceName ("");
            MAPNODE mainnode = GetEntityMainAttribNode(objDevice);
            if(mainnode != INVALID_VALUE)
                FindNodeValue(mainnode, "sv_name", szDeviceName);
            
            int nIndex = 0;
            base_param monitor;
            for(lstItem = lsMonitorID.begin(); lstItem != lsMonitorID.end(); lstItem ++)
            {
                string szMonitorId = (*lstItem).c_str();
                OBJECT objMonitor = GetMonitor(szMonitorId, m_szIDCUser, m_szIDCPwd);
                if(objMonitor != INVALID_VALUE)
                {
                    MAPNODE node = GetMonitorMainAttribNode(objMonitor);
                    if(node != INVALID_VALUE)
                    {
                        string szName (""), szIndex ("");
                        FindNodeValue(node, "sv_name", szName);
                        FindNodeValue(node, "sv_index", szIndex);
                        if(szIndex.empty())
                            nIndex = FindIndexByID(szMonitorId);
                        else
                            nIndex = atoi(szIndex.c_str());

                        monitor.szIndex = szMonitorId;
                        monitor.szName = szDeviceName + ":" + szName;
                        m_sortList[nIndex] = monitor;
                    }
                    CloseMonitor(objMonitor);
                }
            }
        }
        CloseEntity(objDevice);
    }
}
示例#6
0
	virtual void OnApply()
	{
		LRESULT curSel = m_driverList.GetCurSel();
		if (curSel == -1)
			return; // should never happen

		ptrT szName(m_profileName.GetText());
		if (szName == 0)
			return;

		// profile placed in "profile_name" subfolder
		mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, szName, szName);
		m_pd->newProfile = 1;
		m_pd->dblink = (DATABASELINK *)m_driverList.GetItemData(curSel);

		if (CreateProfile(m_pd->ptszProfile, m_pd->dblink) == 0)
			SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
		else
			m_pd->bRun = true;
	}
示例#7
0
void SVResString::loadAddGroupStrings(MAPNODE &objNode)
{
    string szName(""), szNameHelp(""), szTitle(""), szAddTip(""),
        szSaveTip(""), szCancelEditTip(""), szNameErr(""), szEditTitle("");

    FindNodeValue(objNode, "IDS_Group_Name",            szName);
    FindNodeValue(objNode, "IDS_Group_Name_Help",       szNameHelp);
    FindNodeValue(objNode, "IDS_Add_Group_Title",       szTitle);
	FindNodeValue(objNode, "IDS_Add_Group_Tip",         szAddTip);
	FindNodeValue(objNode, "IDS_Save_Group_Tip",        szSaveTip);
	FindNodeValue(objNode, "IDS_Cancel_Group_Edit_Tip", szCancelEditTip);
	FindNodeValue(objNode, "IDS_Group_Name_Error",      szNameErr);
	FindNodeValue(objNode, "IDS_Edit_Group_Title",      szEditTitle);

    m_lsResource["IDS_Group_Name"] = szName;
    m_lsResource["IDS_Group_Name_Help"] = szNameHelp;
    m_lsResource["IDS_Add_Group_Title"] = szTitle;
    m_lsResource["IDS_Add_Group_Tip"] = szAddTip;
    m_lsResource["IDS_Save_Group_Tip"] = szSaveTip;
    m_lsResource["IDS_Cancel_Group_Edit_Tip"] = szCancelEditTip;
    m_lsResource["IDS_Group_Name_Error"] = szNameErr;
    m_lsResource["IDS_Edit_Group_Title"] = szEditTitle;
}
示例#8
0
int KernelService::Spawn()
{
  MutexGuard g(m_mutexServer);

	static const char* szKS = "kers-" ;
	static int iID = 0 ;

  upan::string szName(szKS);
  szName += ToString(iID);
	iID++ ;

	int pid ;
	if(ProcessManager::Instance().CreateKernelImage((unsigned)&(KernelService::Server), ProcessManager::GetCurrentProcessID(), false, (unsigned)this, NULL, &pid, szName.c_str()) !=
			ProcessManager_SUCCESS)
	{
		printf("\n Failed to create Kernel Service Process %s", szName.c_str()) ;
		return -1 ;
	}

	m_lServerList.push_back(pid) ;

	return pid ;
}
示例#9
0
//
///查询注册表的串口号,将值存于数组中
///本代码参考于mingojiang的获取串口逻辑名代码
//
void CSerialPort::QueryKey(HKEY hKey)
{
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
    //	TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    //	DWORD    cbName;                   // size of name string
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
    DWORD    cchClassName = MAX_PATH;  // size of class string
    DWORD    cSubKeys=0;               // number of subkeys
    DWORD    cbMaxSubKey;              // longest subkey size
    DWORD    cchMaxClass;              // longest class string
    DWORD    cValues;              // number of values for key
    DWORD    cchMaxValue;          // longest value name
    DWORD    cbMaxValueData;       // longest value data
    DWORD    cbSecurityDescriptor; // size of security descriptor
    FILETIME ftLastWriteTime;      // last write time

    DWORD i, retCode;

    TCHAR  achValue[MAX_VALUE_NAME];
    DWORD cchValue = MAX_VALUE_NAME;

    // Get the class name and the value count.
    retCode = RegQueryInfoKey(
                  hKey,                    // key handle
                  achClass,                // buffer for class name
                  &cchClassName,           // size of class string
                  NULL,                    // reserved
                  &cSubKeys,               // number of subkeys
                  &cbMaxSubKey,            // longest subkey size
                  &cchMaxClass,            // longest class string
                  &cValues,                // number of values for this key
                  &cchMaxValue,            // longest value name
                  &cbMaxValueData,         // longest value data
                  &cbSecurityDescriptor,   // security descriptor
                  &ftLastWriteTime);       // last write time

    for (i = 0; i<MaxSerialPortNum; i++)///存放串口号的数组初始化
    {
        m_nComArray[i] = -1;
    }

    // Enumerate the key values.
    if (cValues > 0) {
        for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) {
            cchValue = MAX_VALUE_NAME;
            achValue[0] = '\0';
            if (ERROR_SUCCESS == RegEnumValue(hKey, i, achValue, &cchValue, NULL, NULL, NULL, NULL))  {
                CString szName(achValue);
                if (-1 != szName.Find(_T("Serial")) || -1 != szName.Find(_T("VCom")) ) {
                    BYTE strDSName[10];
                    memset(strDSName, 0, 10);
                    DWORD nValueType = 0, nBuffLen = 10;
                    if (ERROR_SUCCESS == RegQueryValueEx(hKey, (LPCTSTR)achValue, NULL, &nValueType, strDSName, &nBuffLen)) {
                        int nIndex = -1;
                        while(++nIndex < MaxSerialPortNum) {
                            if (-1 == m_nComArray[nIndex]) {
                                m_nComArray[nIndex] = atoi((char*)(strDSName + 3));
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    else {
        AfxMessageBox(_T("本机没有串口....."));
    }

}
/////////////////////////////////////////////////////////////
// SAVE PARTICLE EMITTER
/////////////////////////////////////////////////////////////
DWORD CParticleLoader::OnSaveParticleFile(DWORD size, void *params)
{
	VERIFY_MESSAGE_SIZE(size, sizeof(TCHAR *));
	TCHAR *pFilepath = (TCHAR *)params;

	StdString szFilename = ExtractFileName(pFilepath);
	CHashString hszFilename(szFilename);

	StdString szFilepath(pFilepath);
	CHashString hszFilepath(pFilepath);

	DWORD result;
	
	// Check to see that Emitter Exists
	static DWORD msgHash_FindObject = CHashString(_T("FindObject")).GetUniqueID();
	FINDOBJECTPARAMS param;
	param.hszName = &hszFilepath;
	result = m_ToolBox->SendMessage(msgHash_FindObject, sizeof(FINDOBJECTPARAMS), &param);
	if (param.bFound == false)
	{
		//Object does not exist to save out.
		return MSG_ERROR;
	}

	// Create XMLArchive using IXML
	IXMLArchive *XMLar;
	CHashString streamType(_T("File"));

	CREATEARCHIVE ca;
	ca.mode = STREAM_MODE_WRITE;
	ca.streamData = pFilepath;
	ca.streamType = &streamType;
	static DWORD msgHash_CreateXMLArchive = CHashString(_T("CreateXMLArchive")).GetUniqueID();
	result = EngineGetToolBox()->SendMessage(msgHash_CreateXMLArchive, sizeof(CREATEARCHIVE), &ca);
	if( result == MSG_ERROR )
	{
		return MSG_ERROR;
	}

	XMLar = dynamic_cast<IXMLArchive *>(ca.archive);
	if( !XMLar )
	{
		return MSG_ERROR;
	}

	// Create MemArchive using IAR
	IArchive *MemArchive;
	CHashString memType(_T("Memory"));

	CREATEARCHIVE caOut;
	caOut.mode = STREAM_MODE_READ | STREAM_MODE_WRITE;
	caOut.streamData = NULL;
	caOut.streamSize = 0;
	caOut.streamType = &memType;
	static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
	if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &caOut) != MSG_HANDLED)
	{
		XMLar->Close();
		return MSG_ERROR;
	}
	MemArchive = caOut.archive;

	// Change the Memarchive to write
	MemArchive->SetIsWriting(true);

	// Serialize out Emitter Data
	SERIALIZEOBJECTPARAMS sop;
	sop.archive = MemArchive;
	sop.name = &hszFilepath;
	static DWORD msgHash_SerializeObject = CHashString(_T("SerializeObject")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_SerializeObject, sizeof(SERIALIZEOBJECTPARAMS), &sop, NULL, NULL);

	// EMITTER PARSE VALUES
	StdString	szName(_T("ParticleEmitter"));
	StdString	szBrush(_T("Brush"));
	StdString	szKeyframe(_T("Keyframe"));

//	StdString	szDummy;
	float time = 0.0f;
	float value = 0.0f;
	StdString szEmitterName;
	int numBrushes = 0;
	int numKeyframes = 0;
	StdString	szBrushFilepath;
	StdString	szPropertyName;
	
	// Change the Memarchive to read
	MemArchive->SetIsWriting(false);

//	MemArchive->Read( szDummy, _T("filename"));
	MemArchive->Read( szEmitterName, _T("name"));
	MemArchive->Read( numBrushes, _T("brushes"));
	MemArchive->Read( numKeyframes, _T("keyframes"));

	XMLar->StartClass(szName);
		XMLar->Write(szEmitterName, _T("name"));
		XMLar->Write(numBrushes, _T("brushes"));
		XMLar->Write(numKeyframes, _T("keyframes"));

		for (int i = 0; i < numBrushes; i++)
		{	
			MemArchive->Read( szBrushFilepath, _T("Brush") );

			XMLar->StartClass( szBrush );
				XMLar->Write( szBrushFilepath, _T("file") );
			XMLar->EndClass();
		}

		for ( int i = 0; i < numKeyframes; i++ )
		{
			MemArchive->Read( szPropertyName, _T("type") );
			MemArchive->Read( time, _T("time") );
			MemArchive->Read( value, _T("value") );

			XMLar->StartClass( szKeyframe );
				XMLar->Write( szPropertyName, _T("type") );
				XMLar->Write( time, _T("time") );
				XMLar->Write( value, _T("value") );
			XMLar->EndClass();
		}
	XMLar->EndClass();

	MemArchive->Close();
	XMLar->Close();

	return MSG_HANDLED_STOP;
}
示例#11
0
文件: enumser.cpp 项目: yoszka/WinAPI
BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
  friendlyNames.clear();
#else
  ports.RemoveAll();
  friendlyNames.RemoveAll();
#endif  

  //What will be the return value
  BOOL bSuccess = FALSE;

  //Create the WBEM locator
  ATL::CComPtr<IWbemLocator> locator;
  HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&locator));
  if (SUCCEEDED(hr))
  {
    ATL::CComPtr<IWbemServices> services;
    hr = locator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &services);
    if (SUCCEEDED(hr))
    {
      //Execute the query
      ATL::CComPtr<IEnumWbemClassObject> classObject;
      hr = services->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &classObject);
      if (SUCCEEDED(hr))
      {
        bSuccess = TRUE;

        //Now enumerate all the ports
        hr = WBEM_S_NO_ERROR;

        //Final Next will return WBEM_S_FALSE
        while (hr == WBEM_S_NO_ERROR)
        {
          ULONG uReturned = 0;
          ATL::CComPtr<IWbemClassObject> apObj[10];
          hr = classObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
          if (SUCCEEDED(hr))
          {
            for (ULONG n=0; n<uReturned; n++)
            {
              ATL::CComVariant varProperty1;
              HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
              if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
              {
                //If it looks like "COMX" then add it to the array which will be returned
                if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE))
                {
                  //Work out the port number
                  int nPort = _wtoi(&(varProperty1.bstrVal[3]));
                #if defined CENUMERATESERIAL_USE_STL
                  ports.push_back(nPort);
                #else
                  ports.Add(nPort);
                #endif

                  //Also get the friendly name of the port
                  ATL::CComVariant varProperty2;
                  if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
                  {  
                #if defined CENUMERATESERIAL_USE_STL
                  #if defined _UNICODE  
                    std::wstring szName(varProperty2.bstrVal);
                  #else
                    std::string szName(ATL::CW2A(varProperty2.bstrVal));
                  #endif
                    friendlyNames.push_back(szName);
                  #else
                    friendlyNames.Add(CString(varProperty2.bstrVal));    
                  #endif
                  }
                  else
                  {
                  #if defined CENUMERATESERIAL_USE_STL
                    friendlyNames.push_back(_T(""));
                  #else
                    friendlyNames.Add(_T(""));
                  #endif  
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  return bSuccess;
}
示例#12
0
// -------------------------------------------------------------
void Actions::ParseDirectory( LPCTSTR rootPath, LPCTSTR extentionPath  )
{
  // make sure that we do not have too many actions
  // this is a sign that something is broken
  // or that we are reading the root directory
  {
    myodd::threads::Lock guard(_mutexActions);
    if (_actions.size() > static_cast<size_t>(::myodd::config::Get(L"paths\\maxcommand", 2048)))
    {
      ASSERT(0); // you have reached the limit!
                   // it is pointless to try and add more command.
      return;
    }
  }

  // make sure that the path that we have is valid.
  ASSERT( _tcslen( rootPath ) > 0 );
  if( _tcslen( rootPath ) == 0 )
  {
    return;
  }

  //  the end path
  std::wstring directory = rootPath;  

  // make sure it has a trailing back slash.
  myodd::files::AddTrailingBackSlash( directory );

  // add the extension
  directory += extentionPath;

  //  add a trailing back slash
  myodd::files::AddTrailingBackSlash( directory );

  //
  //  we could refine the search to
  //  *.bat, *.exe, *.pl
  //  but I am not sure we really need to restrict anything
  // it is up to the user to ensure that they have 
  auto sPath = directory + L"*.*";

  LPTSTR fullPath = NULL;
  if( !myodd::files::ExpandEnvironment( sPath.c_str(), fullPath ) )
  {
    return;
  }
  
  _tfinddata_t fdata;
  const auto ffhandle = _tfindfirst( fullPath, &fdata );
  if( ffhandle != -1 )
  {
    do
    {
      if( _tcscmp(fdata.name, L"." ) == 0 || _tcscmp(fdata.name, L"..") == 0)
      {
        continue;
      }

      //  .svn directories are hidden so we might as well ignore all hidden file.
      if( (fdata.attrib & _A_HIDDEN) == _A_HIDDEN )
      {
        continue;
      }

      if( (fdata.attrib & _A_SUBDIR) == _A_SUBDIR )
      {
        if( IsReservedDir( fdata.name ) )
        {
          continue;
        }
        
        std::wstring subPath( extentionPath );
        subPath += fdata.name;
        myodd::files::AddTrailingBackSlash( subPath );

        ParseDirectory( rootPath, subPath.c_str() );
        continue;
      }

      //  ok add this command
      auto szFullPath( directory);
      szFullPath += fdata.name;

      std::wstring szName( fdata.name);
      szName = myodd::strings::lower(szName );
      
      //  if we don't want to show the extension then strip it.
      if( ::myodd::config::Get( L"commands\\show.extentions", 0 ) == false )
      {
        myodd::files::StripExtension( szName );
      }        

      Add( new Action( _application ,szName, szFullPath));
    }while( _tfindnext( ffhandle, &fdata ) == 0 );

    _findclose( ffhandle );
  }

  delete [] fullPath;
}
示例#13
0
bool CSVWholeview::enumMonitors(const string &szDeviceID, const string &szDeviceName, WTableCell *pTableCell)
{
    map<int, base_param, less<int> > sortList;
    map<int, base_param, less<int> >::iterator lsItem;

    OBJECT objDevice = GetEntity(szDeviceID,  m_szIDCUser, m_szIDCPwd);
    if(objDevice != INVALID_VALUE)
    {
        list<string> lsMonitorID;
        list<string>::iterator lstItem;
        if (GetSubMonitorsIDByEntity(objDevice, lsMonitorID))
        {
            base_param monitor;
            string szMonitorId("");
            OBJECT objMonitor = INVALID_VALUE;
            MAPNODE node = INVALID_VALUE;

            string szName(""), szIndex("");

            int nIndex = 0;
            for(lstItem = lsMonitorID.begin(); lstItem != lsMonitorID.end(); lstItem ++)
            {
                szMonitorId = (*lstItem).c_str();
                objMonitor = GetMonitor(szMonitorId, m_szIDCUser, m_szIDCPwd);
                if(objMonitor != INVALID_VALUE)
                {
                    node = GetMonitorMainAttribNode(objMonitor);
                    if(node != INVALID_VALUE)
                    {
                        FindNodeValue(node, "sv_name", szName);
                        FindNodeValue(node, "sv_index", szIndex);
                        if(szIndex.empty())
                            nIndex = FindIndexByID(szMonitorId);
                        else
                            nIndex = atoi(szIndex.c_str());
                        monitor.szIndex = szMonitorId;
                        monitor.szName = szName;

                        lsItem = sortList.find(nIndex);
                        while(lsItem != sortList.end())
                        {
                            nIndex ++;//= nMax;
                            lsItem = sortList.find(nIndex);
                        }
                        sortList[nIndex] = monitor;
                    }
                    CloseMonitor(objMonitor);
                }
            }
        }
        CloseEntity(objDevice);
    }
    string szShowText(""), szContent("");
    int nState = dyn_normal;
    bool bShowDevice = false;

    for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
    {
        // get monitor's current state
        nState = getMonitorState(lsItem->second.szIndex, szShowText);
        WImage *pMonitor = NULL;
        if(m_nShowType == -1 || m_nShowType == nState || 
            (m_nShowType == dyn_normal && nState == dyn_no_data) ||
            (m_nShowType == dyn_error && nState == dyn_bad))
        {
            bShowDevice = true;
            pMonitor = new WImage("/Images/state_green.gif", pTableCell);
        }
        if(pMonitor)
        {   
            // change show image by state
            switch(nState)
            {
            case dyn_no_data:
                pMonitor->setImageRef("/Images/state_grey.gif");
                break;
            case dyn_normal:
                pMonitor->setImageRef("/Images/state_green.gif");
                break;
            case dyn_warnning:
                pMonitor->setImageRef("/Images/state_yellow.gif");
                break;
            case dyn_error:
            case dyn_bad:
                pMonitor->setImageRef("/Images/state_red.gif");
                break;
            case dyn_disable:
                pMonitor->setImageRef("/Images/state_stop.gif");
                break;
            }

            // monitor's style && onclick event
            szContent = "style='cursor:pointer;' onclick = 'window.open(\"SimpleReport.exe?id=" + lsItem->second.szIndex + "\");'";
            sprintf(pMonitor->contextmenu_, szContent.c_str());
            pMonitor->setToolTip(szDeviceName + ":" + lsItem->second.szName + "\r\n" + szShowText);
        }
    }
    return bShowDevice;
}
示例#14
0
bool CSVWholeview::enumGroups(const string &szGroupID, WTable *pTable)
{
    bool bShowGroup = false;
	bool gShowGroup = true;//jansion
	bool mShowGroup = true; //jansion
	pTable->setStyleClass("widthauto");
    if(!szGroupID.empty())
    {     
        OBJECT objGroup = GetGroup(szGroupID);
        if(objGroup != INVALID_VALUE)
        { 
			//PrintDebugString("In ------------------------------------\n");
            string szIndex(""), szName(""), szShowIndex(""), szContext("");
            string szShow(""), szHide(""), szSubTable("");
            string szShowText(""), szHideText("");
            bool bHasRight = true;
            int nIndex = 0, nRow = 0; 
            MAPNODE node = INVALID_VALUE;
            list<string> lsGroupID;
            list<string> lsDeviceID;
            list<string>::iterator lstItem;
			//list<string>::iterator bcompItem;

            if(GetSubGroupsIDByGroup(objGroup, lsGroupID))
            {
				
                map<int, base_param, less<int> > sortList;
                map<int, base_param, less<int> >::iterator lsItem;
				map<int, base_param, less<int> >::iterator bcompItem;

				//bool gShow = false;

                base_param group;
                OBJECT objSubGroup = INVALID_VALUE;
                for(lstItem = lsGroupID.begin(); lstItem != lsGroupID.end(); lstItem ++)
                {
					//PrintDebugString("In --------------- for ---------------------\n");
                    szIndex =(*lstItem);
                    bHasRight = true;
                    if(m_pSVUser)
                        bHasRight = m_pSVUser->haveGroupRight(szIndex, Tree_GROUP);
                    if(bHasRight)
                    {
                        objSubGroup = GetGroup(szIndex, m_szIDCUser, m_szIDCPwd);
                        if(objGroup != INVALID_VALUE)
                        {
                            node = GetGroupMainAttribNode(objSubGroup);
                            if(node != INVALID_VALUE)
                            { 
                                FindNodeValue(node, "sv_name", szName);
                                FindNodeValue(node, "sv_index", szShowIndex);
                                if(szShowIndex.empty())
                                    nIndex = FindIndexByID(szIndex);
                                else
                                    nIndex = atoi(szShowIndex.c_str());
                                group.szIndex = szIndex;
                                group.szName = szName;

                                lsItem = sortList.find(nIndex);
                                while(lsItem != sortList.end())
                                {
                                    nIndex ++;
                                    lsItem = sortList.find(nIndex);
                                }
                                sortList[nIndex] = group;
                            }							
							else
							{
								gShowGroup = false;
							}
                            CloseGroup(objSubGroup);
                        }
                    }
					else
					{
						gShowGroup =false;
					}
                }

				//if (lsGroupID.empty())
				//	PrintDebugString("In group is ====== false\n");

                for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
                {					
					//PrintDebugString("In emnuGroup " + lsItem->second.szName + "\n");

					//bool gShow = false;

                    nRow = pTable->numRows();
                    //WImage *pShow = new WImage("../Images/foldopen.gif", pTable->elementAt(nRow, 0));
                    //WImage *pHide = new WImage("../Images/foldclose.gif", pTable->elementAt(nRow, 0));
					//if(!enumGroups(lsItem->second.szIndex, pSub))
					//{
                    WImage *pShow = new WImage("/Images/cb1-unwrap.gif", pTable->elementAt(nRow, 0));
                    WImage *pHide = new WImage("/Images/cb1-fold.gif", pTable->elementAt(nRow, 0));
					//}


					new WText("&nbsp;",pTable->elementAt(nRow, 0));

                    //new WImage("../Images/group.gif", pTable->elementAt(nRow, 1));
					new WImage("/Images/cbb-3group.gif", pTable->elementAt(nRow, 1));
					new WText("&nbsp;",pTable->elementAt(nRow, 1));

                    WText *pName = new WText(lsItem->second.szName, pTable->elementAt(nRow, 2));
                    if(pName)
                    {
                        szContext = "onclick='parent.document.frames(\"left\").location.replace(\"/fcgi-bin/menu.exe?cmd=treeview.exe?groupid=" + lsItem->second.szIndex 
                            + "\");' style='color:#669;cursor:pointer;' onmouseover='this.style.textDecoration=\"underline\"'"
                            + "onmouseout='this.style.textDecoration=\"none\"'";
                        sprintf(pName->contextmenu_, szContext.c_str());
                    }
                    WTable * pSub = new WTable(pTable->elementAt(nRow + 1, 2));
                    if(pSub)
                    {          
                        if(pShow && pHide)
                        {
                            szShow = pHide->formName();
                            szHide = pShow->formName();
                            szSubTable = pSub->formName();

                            szShowText = "onclick='showsubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='display:none;cursor:pointer'";
                            szHideText = "onclick='hidesubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='cursor:pointer'";
                            sprintf(pShow->contextmenu_, szShowText.c_str());
                            sprintf(pHide->contextmenu_, szHideText.c_str());            
                        }

                        if(!enumGroups(lsItem->second.szIndex, pSub))
						{
							//gShow = true;
							//pTable->deleteRow(nRow);
							pShow->hide();
							pHide->hide();
						}
                        else
						{
                            //bShowGroup = true;
							//pShow->hide();
							//pHide->hide();
						}
                    }

                }

				if (sortList.empty())
					gShowGroup = false;

            }
			else
			{
				gShowGroup = false;
			}
            if(GetSubEntitysIDByGroup(objGroup, lsDeviceID))
            {
                map<int, base_param, less<int> > sortList;
                map<int, base_param, less<int> >::iterator lsItem;
                base_param device;
                OBJECT objDevice = INVALID_VALUE;
                for(lstItem = lsDeviceID.begin(); lstItem != lsDeviceID.end(); lstItem ++)
                {
                    szIndex =(*lstItem);
                    bHasRight = true;
                    if(m_pSVUser)
                        bHasRight = m_pSVUser->haveGroupRight(szIndex, Tree_DEVICE);
                    if(bHasRight)
                    {
                        objDevice = GetEntity(szIndex, m_szIDCUser, m_szIDCPwd);
                        if(objDevice != INVALID_VALUE)
                        {
                            node = GetEntityMainAttribNode(objDevice);
                            if(node != INVALID_VALUE)
                            {
                                FindNodeValue(node, "sv_name", szName);
                                FindNodeValue(node, "sv_index", szShowIndex);
                                if(szShowIndex.empty())
                                    nIndex = FindIndexByID(szIndex);
                                else
                                    nIndex =  atoi(szShowIndex.c_str());
                                device.szIndex = szIndex;
                                device.szName = szName;

                                lsItem = sortList.find(nIndex);
                                while(lsItem != sortList.end())
                                {
                                    nIndex ++;
                                    lsItem = sortList.find(nIndex);
                                }
                                sortList[nIndex] = device;
                            }
							else
							{
								mShowGroup = false;
							}
                            CloseEntity(objDevice);
                        }
                    }
                }
                for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
                {
					//PrintDebugString("In emnuGroup " + lsItem->second.szName + "------------------------\n");
                    nRow = pTable->numRows();
                    //new WImage("../Images/device.gif", pTable->elementAt(nRow, 1));
					new WImage("/Images/cbb-4server.gif", pTable->elementAt(nRow, 1));
					new WText("&nbsp;",pTable->elementAt(nRow, 1));

                    WText *pName = new WText(lsItem->second.szName, pTable->elementAt(nRow, 2));
                    if(pName)
                    {
                        szContext = "onclick='parent.document.frames(\"left\").location.replace(\"/fcgi-bin/menu.exe?cmd=treeview.exe?deviceid=" + lsItem->second.szIndex 
                            + "\");' style='color:#669;cursor:pointer;' onmouseover='this.style.textDecoration=\"underline\"'"
                            + "onmouseout='this.style.textDecoration=\"none\"'";
                        sprintf(pName->contextmenu_, szContext.c_str());
                    }
                    if(!enumMonitors(lsItem->second.szIndex, lsItem->second.szName, pTable->elementAt(nRow, 2)))
					{
						bShowGroup = false;
						//bShowGroup = true;
                        //pTable->deleteRow(nRow);
					}
                    else
                        bShowGroup = true;
                }

				//84200891
				if (sortList.empty())
				{
					mShowGroup = false;
				}

            }
			else
			{
				mShowGroup = false;
			}
            CloseGroup(objGroup);
        }
		else
		{
			mShowGroup = false;
			gShowGroup = false;
		}
    }
	else
	{
		mShowGroup = false;
		gShowGroup = false;
	}

	bool bbShowGroup;
	bbShowGroup = gShowGroup || mShowGroup;
    return bbShowGroup;
}
示例#15
0
void CSVWholeview::enumSVSE()
{
    if(!m_pContent)
        return;

    PAIRLIST selist;
    string szRootname("");
    int nRow = 0;

    WTable *pTable = m_pContent;
    if(GetIniFileInt("solover","solover",1,"general.ini") == 1)
    {       
        sv_pair svpair;
        svpair.name = "1";
        OBJECT objSE = GetSVSE("1");//, m_szIDCUser, m_szIDCPwd);
        if(objSE != INVALID_VALUE)
        {
            svpair.value = GetSVSELabel(objSE);
            CloseSVSE(objSE);
        }        
        selist.push_back(svpair);
    }
    else
    {
        GetAllSVSEInfo(selist);
        szRootname = GetIniFileString("segroup","name","","general.ini");
        if(szRootname.empty())
            szRootname = "SiteView ECC 7.0";        
        nRow = m_pContent->numRows();
        //WImage *pShow = new WImage("../Images/foldopen.gif", m_pContent->elementAt(nRow, 0));
        //WImage *pHide = new WImage("../Images/foldclose.gif", m_pContent->elementAt(nRow, 0));
        WImage *pShow = new WImage("/Images/cb1-unwrap.gif", m_pContent->elementAt(nRow, 0));
        WImage *pHide = new WImage("/Images/cb1-fold.gif", m_pContent->elementAt(nRow, 0));

		new WText("&nbsp;",m_pContent->elementAt(nRow, 0));

        //new WImage("../Images/home.gif", m_pContent->elementAt(nRow, 1));
		new WImage("/Images/cbb-2main.gif", m_pContent->elementAt(nRow, 1));

		new WText("&nbsp;",m_pContent->elementAt(nRow, 1));

        WText *pName = new WText(szRootname, m_pContent->elementAt(nRow, 2));
        if(pName)
        {
            sprintf(pName->contextmenu_, "style='color:#669;cursor:pointer;' onmouseover='" \
                "this.style.textDecoration=\"underline\"' " \
                "onmouseout='this.style.textDecoration=\"none\"'");
        }
        pTable = new WTable(m_pContent->elementAt(nRow + 1, 2));
		pTable->setStyleClass("widthauto");
        if(!pTable)
            return;
        else
        {
            if(pShow && pHide)
            {
                string szShow = "", szHide = "", szSubTable = "";
                szShow = pHide->formName();
                szHide = pShow->formName();
                szSubTable = pTable->formName();

                string szShowText = "onclick='showsubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='display:none;cursor:pointer'";
                string szHideText = "onclick='hidesubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='cursor:pointer'";
                sprintf(pShow->contextmenu_, szShowText.c_str());
                sprintf(pHide->contextmenu_, szHideText.c_str());            
            }
        }
    }

    PAIRLIST::iterator iSe;
    
    bool bHasRight = true;

    int  nChildCount = 0, nIndex = 0;

    OBJECT objSE = INVALID_VALUE;
    OBJECT objGroup = INVALID_VALUE;
    MAPNODE node = INVALID_VALUE;

    string szSEID(""), szSubGroupID(""), szEntityID("");
    string szName(""), szIndex("");
    string szContext(""), szShow(""), szHide(""), szSubTable("");
    string szShowText(""), szHideText("");

    list<string> lsGroupID;
    list<string> lsDeviceID;
    list<string>::iterator lstItem;

    for(iSe= selist.begin(); iSe!=selist.end(); iSe++)
    {
        szSEID = (*iSe).name;
        bHasRight = true;
        if(m_pSVUser)
            bHasRight = m_pSVUser->haveGroupRight(szSEID, Tree_SE);
        if(bHasRight)
        {
            nRow = pTable->numRows();
            //WImage *pShow = new WImage("../Images/foldopen.gif", pTable->elementAt(nRow, 0));
            //WImage *pHide = new WImage("../Images/foldclose.gif", pTable->elementAt(nRow, 0));
            WImage *pShow = new WImage("/Images/cb1-unwrap.gif", pTable->elementAt(nRow, 0));
            WImage *pHide = new WImage("/Images/cb1-fold.gif", pTable->elementAt(nRow, 0));
           
			new WText("&nbsp;",pTable->elementAt(nRow, 0));

			new WImage("/Images/cbb-2main.gif", pTable->elementAt(nRow, 1));

			new WText("&nbsp;",pTable->elementAt(nRow, 1));

            WText *pName = new WText((*iSe).value, pTable->elementAt(nRow, 2));
            if(pName)
            {
                szContext = "onclick='parent.document.frames(\"left\").location.replace(\"/fcgi-bin/menu.exe?cmd=treeview.exe?svseid=" + szSEID 
                    + "\");' style='color:#669;cursor:pointer;' onmouseover='this.style.textDecoration=\"underline\"'"
                    + "onmouseout='this.style.textDecoration=\"none\"'";
                sprintf(pName->contextmenu_, szContext.c_str());
            }
            WTable *pSubTable = new WTable(pTable->elementAt(nRow + 1, 2));
			pSubTable->setStyleClass("widthauto");
            if(!pSubTable)
                return;
            else
            {
                if(pShow && pHide)
                {                    
                    szShow = pHide->formName();
                    szHide = pShow->formName();
                    szSubTable = pSubTable->formName();

                    szShowText = "onclick='showsubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='display:none;cursor:pointer'";
                    szHideText = "onclick='hidesubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='cursor:pointer'";
                    sprintf(pShow->contextmenu_, szShowText.c_str());
                    sprintf(pHide->contextmenu_, szHideText.c_str());            
                }
            }
            
            objSE = GetSVSE(szSEID);
            if(objSE != INVALID_VALUE)
            {
                lsGroupID.clear();
                if(GetSubGroupsIDBySE(objSE, lsGroupID))
			    {
                    map<int, base_param, less<int> > sortList;
                    map<int, base_param, less<int> >::iterator lsItem;
					map<int, base_param, less<int> >::iterator compItem;

                    base_param group;

                    for(lstItem = lsGroupID.begin(); lstItem != lsGroupID.end(); lstItem ++)
                    {
                        szSubGroupID =(*lstItem);
                        bHasRight = true;
                        if(m_pSVUser)
                            bHasRight = m_pSVUser->haveGroupRight(szSubGroupID, Tree_GROUP);
                        if(bHasRight)
                        {
                            objGroup = GetGroup(szSubGroupID, m_szIDCUser, m_szIDCPwd);
                            if(objGroup != INVALID_VALUE)
                            {
                                node = GetGroupMainAttribNode(objGroup);
                                if(node != INVALID_VALUE)
                                {
                                    FindNodeValue(node, "sv_name", szName);
                                    FindNodeValue(node, "sv_index", szIndex);

                                    if(szIndex.empty())
                                        nIndex = FindIndexByID(szSubGroupID);
                                    else
                                        nIndex = atoi(szIndex.c_str());

                                    group.szIndex = szSubGroupID;
                                    group.szName = szName;

                                    lsItem = sortList.find(nIndex);
                                    while(lsItem != sortList.end())
                                    {
                                        nIndex ++;
                                        lsItem = sortList.find(nIndex);
                                    }
                                    sortList[nIndex] = group;
                                }
                                CloseGroup(objGroup);
                            }
                        }
                    }
                    nChildCount += static_cast<int>(sortList.size());

                    for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
                    {
						//PrintDebugString("In first setting ---------" + lsItem->second.szName + "\n");
						//bool bbbb = false;
                        nRow = pSubTable->numRows();
					    WImage *pShow = new WImage("/Images/cb1-unwrap.gif", pSubTable->elementAt(nRow, 0));
					    WImage *pHide = new WImage("/Images/cb1-fold.gif", pSubTable->elementAt(nRow, 0));

						new WText("&nbsp;",pSubTable->elementAt(nRow, 0));

						new WImage("/Images/cbb-3group.gif", pSubTable->elementAt(nRow, 1));

						new WText("&nbsp;",pSubTable->elementAt(nRow, 1));

                        WText *pName = new WText(lsItem->second.szName, pSubTable->elementAt(nRow, 2));
                        if(pName)
                        {
                            string szContext = "onclick='parent.document.frames(\"left\").location.replace(\"/fcgi-bin/menu.exe?cmd=treeview.exe?groupid=" + lsItem->second.szIndex 
                                + "\");' style='color:#669;cursor:pointer;' onmouseover='this.style.textDecoration=\"underline\"'"
                                + "onmouseout='this.style.textDecoration=\"none\"'";
                            sprintf(pName->contextmenu_, szContext.c_str());
                        }
                        WTable * pSub = new WTable(pSubTable->elementAt(nRow + 1, 2));
                        if(pSub)
                        {                        
                            if(pShow && pHide)
                            {
                                szShow = pHide->formName();
                                szHide = pShow->formName();
                                szSubTable = pSub->formName();

                                string szShowText = "onclick='showsubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='display:none;cursor:pointer'";
                                string szHideText = "onclick='hidesubtable(\"" + szShow + "\", \"" + szHide + "\", \"" + szSubTable + "\")' " + "style='cursor:pointer'";
                                sprintf(pShow->contextmenu_, szShowText.c_str());
                                sprintf(pHide->contextmenu_, szHideText.c_str());            
                            }
                            if(!enumGroups(lsItem->second.szIndex, pSub))
							{
								//bbbb = true;
                                //pSubTable->deleteRow(nRow);
								pShow->hide();
								pHide->hide();

							}
                        }
                    }

                }
                lsDeviceID.clear();
                if(GetSubEntitysIDBySE(objSE, lsDeviceID))
                {
                    map<int, base_param, less<int> > sortList;
                    map<int, base_param, less<int> >::iterator lsItem;
                    base_param device;
                    for(lstItem = lsDeviceID.begin(); lstItem != lsDeviceID.end(); lstItem ++)
                    {
                        szEntityID =(*lstItem);
                        bHasRight = true;
                        if(m_pSVUser)
                            bHasRight = m_pSVUser->haveGroupRight(szEntityID, Tree_DEVICE);
                        if(bHasRight)
                        {
                            OBJECT objDevice = GetEntity(szEntityID, m_szIDCUser, m_szIDCPwd);
                            if(objDevice != INVALID_VALUE)
                            {
                                MAPNODE node = GetEntityMainAttribNode(objDevice);
                                if(node != INVALID_VALUE)
                                {
                                    FindNodeValue(node, "sv_name", szName);
                                    FindNodeValue(node, "sv_index", szIndex);
                                    if(szIndex.empty())
                                        nIndex = FindIndexByID(szEntityID);
                                    else
                                        nIndex = atoi(szIndex.c_str());

                                    device.szIndex = szEntityID;
                                    device.szName = szName;

                                    lsItem = sortList.find(nIndex);
                                    while(lsItem != sortList.end())
                                    {
                                        nIndex ++;
                                        lsItem = sortList.find(nIndex);
                                    }
                                    sortList[nIndex] = device;
                                }
                                CloseEntity(objDevice);
                            }
                        }
                    }
                    nChildCount += static_cast<int>(sortList.size());
                    for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
                    {
                        nRow = pSubTable->numRows();

						new WText("&nbsp;",pSubTable->elementAt(nRow , 0));

						new WImage("/Images/cbb-4server.gif", pSubTable->elementAt(nRow, 1));

						new WText("&nbsp;",pSubTable->elementAt(nRow , 1));

                        WText *pName = new WText(lsItem->second.szName, pSubTable->elementAt(nRow, 2));
                        if(pName)
                        {
                            szContext = "onclick='parent.document.frames(\"left\").location.replace(\"/fcgi-bin/menu.exe?cmd=treeview.exe?deviceid=" + lsItem->second.szIndex 
                                + "\");' style='color:#669;cursor:pointer;' onmouseover='this.style.textDecoration=\"underline\"'"
                                + "onmouseout='this.style.textDecoration=\"none\"'";
                            sprintf(pName->contextmenu_, szContext.c_str());
                        }
                        if(!enumMonitors(lsItem->second.szIndex, lsItem->second.szName, pSubTable->elementAt(nRow, 2)))
						{
							//pSubTable->deleteRow(nRow);
						}

                    }
                }
                CloseSVSE(objSE);

                if(nChildCount <= 0)
                {
                    new WText(m_szNoChild, pSubTable->elementAt(nRow, 2));
                }
            }
        }
    }
}
示例#16
0
BOOL CEnumerateSerial::UsingWMI(CSimpleArray<UINT>& ports, CSimpleArray<CString>& friendlyNames)
#endif
{
  //Make sure we clear out any elements which may already be in the array(s)
#if defined CENUMERATESERIAL_USE_STL
  ports.clear();
  friendlyNames.clear();
#else
  ports.RemoveAll();
  friendlyNames.RemoveAll();
#endif  

  //What will be the return value
  BOOL bSuccess = FALSE;

  //Create the WBEM locator
  IWbemLocator* pLocator = NULL;
  HRESULT hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<void**>(&pLocator));
  if (SUCCEEDED(hr))
  {
    IWbemServices* pServices = NULL;
    hr = pLocator->ConnectServer(_bstr_t("\\\\.\\root\\cimv2"), NULL, NULL, NULL, 0, NULL, NULL, &pServices);
    if (SUCCEEDED(hr))
    {
      //Execute the query
      IEnumWbemClassObject* pClassObject = NULL;
      hr = pServices->CreateInstanceEnum(_bstr_t("Win32_SerialPort"), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &pClassObject);
      if (SUCCEEDED(hr))
      {
        bSuccess = TRUE;

        //Now enumerate all the ports
        hr = WBEM_S_NO_ERROR;

        //Final Next will return WBEM_S_FALSE
        while (hr == WBEM_S_NO_ERROR)
        {
          ULONG uReturned = 0;
          IWbemClassObject* apObj[10];
          memset(apObj, 0, sizeof(apObj));
          hr = pClassObject->Next(WBEM_INFINITE, 10, reinterpret_cast<IWbemClassObject**>(apObj), &uReturned);
          if (SUCCEEDED(hr))
          {
            for (ULONG n=0; n<uReturned; n++)
            {
              VARIANT varProperty1;
              VariantInit(&varProperty1);
              HRESULT hrGet = apObj[n]->Get(L"DeviceID", 0, &varProperty1, NULL, NULL);
              if (SUCCEEDED(hrGet) && (varProperty1.vt == VT_BSTR) && (wcslen(varProperty1.bstrVal) > 3))
              {
                //If it looks like "COMX" then add it to the array which will be returned
                if ((_wcsnicmp(varProperty1.bstrVal, L"COM", 3) == 0) && IsNumeric(&(varProperty1.bstrVal[3]), TRUE))
                {
                  //Work out the port number
                  int nPort = _wtoi(&(varProperty1.bstrVal[3]));
                #if defined CENUMERATESERIAL_USE_STL
                  ports.push_back(nPort);
                #else
                  ports.Add(nPort);
                #endif

                  //Also get the friendly name of the port
                  VARIANT varProperty2;
                  VariantInit(&varProperty2);
                  if (SUCCEEDED(apObj[n]->Get(L"Name", 0, &varProperty2, NULL, NULL)) && (varProperty2.vt == VT_BSTR))
                  {  
                #if defined CENUMERATESERIAL_USE_STL
                  #if defined _UNICODE  
                    std::wstring szName(varProperty2.bstrVal);
                  #else
                    CAutoHeapAlloc szAsciiValue;
                    int nLengthA = WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, NULL, 0, NULL, NULL);
                    if (nLengthA)
                    {
                      if (szAsciiValue.Allocate(nLengthA))
                        WideCharToMultiByte(CP_ACP, 0, varProperty2.bstrVal, -1, static_cast<LPSTR>(szAsciiValue.m_pData), nLengthA, NULL, NULL);
                    }

                    std::string szName(static_cast<LPSTR>(szAsciiValue.m_pData));
                  #endif
                    friendlyNames.push_back(szName);
                  #else
                    friendlyNames.Add(CString(varProperty2.bstrVal));    
                  #endif
                  }
                  else
                  {
                  #if defined CENUMERATESERIAL_USE_STL
                    friendlyNames.push_back(_T(""));
                  #else
                    friendlyNames.Add(_T(""));
                  #endif  
                  }

                  //Free up the variant;
                  VariantClear(&varProperty2);
                }
              }

              //Free up the variant;
              VariantClear(&varProperty1);

              //Free up each COM interface
              apObj[n]->Release();
            }
          }
        }

        //Free up the COM interface
        pClassObject->Release();
      }

      //Free up the COM interface
      pServices->Release();
    }

    //Free up the COM interface
    pLocator->Release();
  }
  
  return bSuccess;
}