Platform SDK: Transaction Server

Count, EnumNames, GetProperty Methods Example

[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]

#include "stdafx.h"
#include <initguid.h>
#include "asptlb.h"
#include "mtx.h"

HRESULT hr = NOERROR;

// Get the context object
CComPtr<IObjectContext> pObjectContext;
hr = GetObjectContext(&pObjectContext);

// Get the Response object
CComVariant v;
CComBSTR bstr(L"Response");
CComQIPtr<IGetContextProperties,     &IID_IGetContextProperties> pProps(pObjectContext);
hr = pProps->GetProperty(bstr, &v);
CComPtr<IDispatch> pDisp;
pDisp = V_DISPATCH(&v);
CComQIPtr<IResponse, &IID_IResponse> pResponse(pDisp);

// Print number of properties
long lCount;
hr = pProps->Count(&lCount);
bstr = L"<p>Number of properties: ";
CComBSTR bstrCount;
VarBstrFromI4(lCount, 0, 0, &bstrCount);
bstr.Append(bstrCount);
bstr.Append(L"</p>");
v = bstr;
hr = pResponse->Write(v);

// Iterate over properties collection and print the
// names of the properties
CComPtr<IEnumNames> pEnum;
CComBSTR bstrTemp;
pProps->EnumNames(&pEnum);
for ( int i = 0; i < lCount; ++i )
{
    pEnum->Next(1, &bstr, NULL);
    bstrTemp = L"<p>";
    bstrTemp.Append(bstr);
    bstrTemp.Append(L"</p>");
    v = bstrTemp;
    hr = pResponse->Write(v);
}