Example #1
0
HRESULT CpiGetCatalogCollection(
	LPCWSTR pwzName,
	ICatalogCollection** ppiColl
	)
{
	HRESULT hr = S_OK;

	ICOMAdminCatalog* piCatalog = NULL;
	IDispatch* piDisp = NULL;

	BSTR bstrName = NULL;

	// copy name string
	bstrName = ::SysAllocString(pwzName);
	ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "Failed to allocate BSTR for collection name");

	// get catalog
	hr = CpiGetAdminCatalog(&piCatalog);
	ExitOnFailure(hr, "Failed to get COM+ admin catalog");

	// get collecton from catalog
	hr = piCatalog->GetCollection(bstrName, &piDisp);
	ExitOnFailure(hr, "Failed to get collection");

	hr = piDisp->QueryInterface(IID_ICatalogCollection, (void**)ppiColl);
	ExitOnFailure(hr, "Failed to get IID_ICatalogCollection interface");

	// populate collection
	hr = (*ppiColl)->Populate();
	if (COMADMIN_E_OBJECTERRORS == hr)
		CpiLogCatalogErrorInfo();
	ExitOnFailure(hr, "Failed to populate collection");

	hr = S_OK;

LExit:
	// clean up
	ReleaseObject(piCatalog);
	ReleaseObject(piDisp);
	ReleaseBSTR(bstrName);

	return hr;
}
Example #2
0
HRESULT CpiGetApplicationsCollection(
    ICatalogCollection** ppiAppColl
    )
{
    HRESULT hr = S_OK;

    ICOMAdminCatalog* piCatalog = NULL;
    ICOMAdminCatalog2* piCatalog2 = NULL;
    ICatalogCollection* piPartColl = NULL;
    ICatalogObject* piPartObj = NULL;
    BSTR bstrGlobPartID = NULL;

    if (!gpiAppColl)
    {
        // get catalog
        hr = CpiGetAdminCatalog(&piCatalog);
        ExitOnFailure(hr, "Failed to get COM+ admin catalog");

        // get ICOMAdminCatalog2 interface
        hr = piCatalog->QueryInterface(IID_ICOMAdminCatalog2, (void**)&piCatalog2);

        // COM+ 1.5 or later
        if (E_NOINTERFACE != hr)
        {
            ExitOnFailure(hr, "Failed to get IID_ICOMAdminCatalog2 interface");

            // get global partition id
            hr = piCatalog2->get_GlobalPartitionID(&bstrGlobPartID);
            ExitOnFailure(hr, "Failed to get global partition id");

            // get partitions collection
            hr = CpiGetPartitionsCollection(&piPartColl);
            ExitOnFailure(hr, "Failed to get partitions collection");

            // find object
            hr = CpiFindCollectionObject(piPartColl, bstrGlobPartID, NULL, &piPartObj);
            ExitOnFailure(hr, "Failed to find collection object");

            if (S_FALSE == hr)
                ExitFunction(); // partition not found, exit with hr = S_FALSE

            // get applications collection
            hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", &gpiAppColl);
            ExitOnFailure(hr, "Failed to get applications collection");
        }

        // COM+ pre 1.5
        else
        {
            // get applications collection
            hr = CpiGetCatalogCollection(L"Applications", &gpiAppColl);
            ExitOnFailure(hr, "Failed to get applications collection");
        }
    }

    // return value
    gpiAppColl->AddRef();
    *ppiAppColl = gpiAppColl;

    hr = S_OK;

LExit:
    // clean up
    ReleaseObject(piCatalog);
    ReleaseObject(piCatalog2);
    ReleaseObject(piPartColl);
    ReleaseObject(piPartObj);
    ReleaseBSTR(bstrGlobPartID);

    return hr;
}
Example #3
0
HRESULT CpiGetApplicationsCollection(
	LPCWSTR pwzPartID,
	ICatalogCollection** ppiAppColl
	)
{
	HRESULT hr = S_OK;

	ICOMAdminCatalog* piCatalog = NULL;
	ICOMAdminCatalog2* piCatalog2 = NULL;
	BSTR bstrGlobPartID = NULL;

	ICatalogCollection* piPartColl = NULL;
	ICatalogObject* piPartObj = NULL;

	// get catalog
	hr = CpiGetAdminCatalog(&piCatalog);
	ExitOnFailure(hr, "Failed to get COM+ admin catalog");

	// get ICOMAdminCatalog2 interface
	hr = piCatalog->QueryInterface(IID_ICOMAdminCatalog2, (void**)&piCatalog2);

	// COM+ 1.5 or later
	if (E_NOINTERFACE != hr)
	{
		ExitOnFailure(hr, "Failed to get IID_ICOMAdminCatalog2 interface");

		// partition id
		if (!pwzPartID || !*pwzPartID)
		{
			// get global partition id
			hr = piCatalog2->get_GlobalPartitionID(&bstrGlobPartID);
			ExitOnFailure(hr, "Failed to get global partition id");
		}

		// get partitions collection
		hr = CpiGetPartitionsCollection(&piPartColl);
		ExitOnFailure(hr, "Failed to get partitions collection");

		// find object
		hr = CpiFindCollectionObjectByStringKey(piPartColl, bstrGlobPartID ? bstrGlobPartID : pwzPartID, &piPartObj);
		ExitOnFailure(hr, "Failed to find collection object");

		if (S_FALSE == hr)
			ExitFunction(); // partition not found, exit with hr = S_FALSE

		// get applications collection
		hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", ppiAppColl);
		ExitOnFailure(hr, "Failed to get catalog collection for partition");
	}

	// COM+ pre 1.5
	else
	{
		// this version of COM+ does not support partitions, make sure a partition was not specified
		if (pwzPartID && *pwzPartID)
			ExitOnFailure(hr = E_FAIL, "Partitions are not supported by this version of COM+");

		// get applications collection
		hr = CpiGetCatalogCollection(L"Applications", ppiAppColl);
		ExitOnFailure(hr, "Failed to get catalog collection");
	}

	hr = S_OK;

LExit:
	// clean up
	ReleaseObject(piCatalog);
	ReleaseObject(piCatalog2);
	ReleaseBSTR(bstrGlobPartID);

	ReleaseObject(piPartColl);
	ReleaseObject(piPartObj);

	return hr;
}