/* static */
std::vector<CBugTraqProvider> CBugTraqAssociations::GetAvailableProviders()
{
	std::vector<CBugTraqProvider> results;

	ICatInformation *pCatInformation = NULL;

	HRESULT hr;
	if (SUCCEEDED(hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL, IID_ICatInformation, (void **)&pCatInformation)))
	{
		IEnumGUID *pEnum = NULL;
		if (SUCCEEDED(hr = pCatInformation->EnumClassesOfCategories(1, &CATID_BugTraqProvider, 0, NULL, &pEnum)))
		{
			HRESULT hrEnum;
			do
			{
				CLSID clsids[5];
				ULONG cClsids;

				hrEnum = pEnum->Next(ARRAYSIZE(clsids), clsids, &cClsids);
				if (SUCCEEDED(hrEnum))
				{
					for (ULONG i = 0; i < cClsids; ++i)
					{
						CBugTraqProvider provider;
						provider.clsid = clsids[i];
						provider.name = LookupProviderName(clsids[i]);
						results.push_back(provider);
					}
				}
			} while (hrEnum == S_OK);
		}

		if (pEnum)
			pEnum->Release();
		pEnum = NULL;
	}

	if (pCatInformation)
		pCatInformation->Release();
	pCatInformation = NULL;

	return results;
}
Ejemplo n.º 2
0
HRESULT OPCEngine::unregisterServer(void)
{ 
	_TRACE(TL_INF, TG_ENG, (_T("unregister server")));
	HRESULT res;

	{
		ICatRegister *cr;
		ICatInformation *ci = NULL ;
		IEnumCLSID* enumCLSID = NULL ;
		CATID catIDs[2];
		CLSID clsid ;

		if (SUCCEEDED(res = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
			NULL, CLSCTX_ALL, IID_ICatRegister, (void **)&cr)))
		{
			// unregister server in categories
			catIDs[0] = CATID_OPCDAServer10;
			catIDs[1] = CATID_OPCDAServer20;
			res = cr->UnRegisterClassImplCategories(g_clsid, 2, catIDs);
			_TRACE(TL_INF, TG_ENG, (_T("unregister component implementations [0x%X]"), res));

			// check if this server was the last in the category
			if (SUCCEEDED(res = cr->QueryInterface(IID_ICatInformation, (void**)&ci)))
			{
				// OPC DA Server V1.0A
				if (SUCCEEDED (res = ci->EnumClassesOfCategories(1, &catIDs[0], 0, NULL, &enumCLSID)))
				{
					res = enumCLSID->Next(1, &clsid, NULL) ;

					// if result is S_FALSE, there no components are in this category, so remove it.
					if (res == S_FALSE)
					{
						// unregister the component category
						res = cr->UnRegisterCategories(1, &catIDs[0]) ;
						_TRACE(TL_INF, TG_ENG, (_T("unregister DA V1.0A component category [0x%X]"), res));
					}
					enumCLSID->Release();
				}

				// OPC DA Server V2.0
				if (SUCCEEDED (res = ci->EnumClassesOfCategories(1, &catIDs[1], 0, NULL, &enumCLSID)))
				{
					res = enumCLSID->Next(1, &clsid, NULL) ;

					// if result is S_FALSE, there no components are in this category, so remove it.
					if (res == S_FALSE)
					{
						// unregister the component category
						res = cr->UnRegisterCategories(1, &catIDs[1]) ;
						_TRACE(TL_INF, TG_ENG, (_T("unregister DA V2.0 component category [0x%X]"), res));
					}
					enumCLSID->Release();
				}

				ci->Release();
			}
			cr->Release();
		}

		CRegKey key, keyCLSID;
		DWORD ret;

		if (ret = keyCLSID.Open(HKEY_CLASSES_ROOT, _T("CLSID")) == ERROR_SUCCESS)
		{
			USES_CONVERSION;
			LPOLESTR wszClsid;
			LPTSTR clsid;
			StringFromCLSID(g_clsid, &wszClsid);
			clsid = W2T(wszClsid);
			CoTaskMemFree(wszClsid);

			if (ret = key.Open(keyCLSID, clsid) == ERROR_SUCCESS)
			{
				key.RecurseDeleteKey(_T("Implemented Categories"));
				key.Close();
			}
			else
				res = HRESULT_FROM_WIN32(ret);

			keyCLSID.Close();
		}
		else
			res = HRESULT_FROM_WIN32(ret);
	}

	// unregister COM Server object
	res = _Module.UnregisterServer();

	return res; 
} // unregisterServer
Ejemplo n.º 3
0
// **************************************************************************
// DisplayComponentCatList ()
//
// Description:
//	Construct a list of installed 1.0 and 2.0 OPC servers and insert into 
//	tree control.
//
// Parameters:
//  HTREEITEM	hParent		Handle of parent tree control item.
//	CATID		catid		Catagory ID (CATID_OPCDAServer10 or
//							  CATID_OPCDAServer20).
//
// Returns:
//  void
// **************************************************************************
void CKServerGeneralPage::DisplayComponentCatList (HTREEITEM hParent, CATID catid)
{
	HRESULT hr;

	// Make sure COM is initialized:
	hr = CoInitializeEx (NULL, COINIT_MULTITHREADED);

	if (SUCCEEDED (hr))
	{
		ICatInformation *pCat = NULL;

		// Get component category manager:
		hr = CoCreateInstance (CLSID_StdComponentCategoriesMgr, 
			NULL,
			CLSCTX_SERVER, 
			IID_ICatInformation,
			(void **)&pCat);

		// If succeeded, enumerate registered components:
		if (SUCCEEDED (hr))
		{
			IEnumCLSID *pEnum = NULL;

			CATID arrcatid [1];
			arrcatid [0] = catid;

			// Enumerate registered components based on clsid:
			hr = pCat->EnumClassesOfCategories (
				sizeof (arrcatid) / sizeof (CATID),	// number of catids in the array that follows
				arrcatid,							// catid array
				0, 
				NULL,
				&pEnum);							// clsid enumerator for registered components under this category

			// If succeeded, process results:
			if (SUCCEEDED (hr))
			{
				GUID guid;
				ULONG fetched;

				// Loop over enumerated components.  Call enemerator's next
				// member function to reference next component and get its
				// guid:
				while ((hr = pEnum->Next (1, &guid, &fetched)) == S_OK)
				{
					// Get the ProgID from the guid:
					WCHAR *wszProgID;
					hr = ProgIDFromCLSID (guid, &wszProgID);

					// If succeeded, add component to list:
					if (SUCCEEDED (hr))
					{
						// ProgID string will be in UNICODE format.  Convert to 
						// ANSI format if this is and ANSI build.  Insert component
						// into list:
					#ifdef _UNICODE
						m_pServerList->InsertItem (wszProgID, ILI_COMPONENT, ILI_COMPONENT, hParent);
					#else
						TCHAR szProgID [DEFBUFFSIZE];

						_wcstombsz (szProgID, wszProgID, sizeof (szProgID) / sizeof (TCHAR));
						m_pServerList->InsertItem (szProgID, ILI_COMPONENT, ILI_COMPONENT, hParent);
					#endif
						// It is up to us to free the Prog ID string memory:
						CoTaskMemFree (wszProgID);
					}
				}

				// Release our enumerator:
				pEnum->Release ();
			}
			// release our category mamager
			pCat->Release ();
		}
		// Uninitialize COM:
		CoUninitialize ();
	}
}
Ejemplo n.º 4
0
void CPluginManager::EnumAllComponent()
{
	HRESULT hr;
	ICatInformation* pCatInfo = NULL;
	hr = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr,
						     NULL, 
						     CLSCTX_ALL, 
						     IID_ICatInformation,
						     (void**)&pCatInfo);
	if(FAILED(hr))
	{
		return;
	}

	CATID IDs[1];
	IDs[0] = CATID_Calc;
	IEnumCLSID *pIEnumCLSID = NULL;
	
	// Returns an enumerator for the component categories - "Calc" 
	// that registered on the system
	hr = pCatInfo->EnumClassesOfCategories(1, IDs, 0, NULL, &pIEnumCLSID);
	if(FAILED(hr))
	{
		return;
	}

	ClearListOfCalcComs();

	int nComCnt = 0;
	CLSID clsid;
	while((hr = pIEnumCLSID->Next(1, &clsid, NULL)) == S_OK)
	{
		ICalc* pIcalc = NULL;
		HRESULT	hr = ::CoCreateInstance(clsid,
			                            NULL,
							            CLSCTX_INPROC_SERVER,
								        IID_ICalc,
								        (void**)&pIcalc);
		if(FAILED(hr))
		{
			continue;
		}

		BSTR pOpName;
		CALCCOMS* pComCalc = new CALCCOMS;
		pComCalc->clsid = clsid;
		pComCalc->iCalc = pIcalc;
		pComCalc->iCalc->GetOpName(&pOpName);
		pComCalc->strOpName = pOpName;
		pComCalc->nButtonID = IDC_COM_BUTTON_BEGIN + nComCnt;
		m_lstCaclComs.AddTail(pComCalc);
		
		nComCnt++;
	}

	if(pIEnumCLSID != NULL)
	{
		pIEnumCLSID->Release();
	}

	if(pCatInfo != NULL)
	{
		pCatInfo->Release();
	}
}