Accessing WebSphere MQ objects using enumeration" /> C++ Language invocation

 

C++ Language invocation

The following code fragment connects to the queue manager called

queue.manager.1 on machine heron and obtains an enumeration of its children. Using the enumeration object obtained, the code then displays information about each child before issuing a count of the number of child objects processed:

//
// Define and initialize variables.
//
 
ULONG cElementFetched = 0L;
IEnumVARIANT *pEnumVariant = NULL;
VARIANT VariantArray[MAX_ADS_ENUM];
IADsContainer *pADsContainer = NULL;
DWORD dwObjects = 0, i = 0;
BOOL fContinue = TRUE;
 
//
// Ensure VARIANT array used to store results is empty
//
 
for (i = 0; i <MAX_ADS_ENUM; i++)
{
    VariantInit(&VariantArray*lbrk.i]);
}
 
//
// Attach to the IADs Container interface for the queue manager
// queue.manager.1 residing on machine heron.
//
 
ADsGetObject( _TEXT("WebSphere MQ://MQHost/heron/MQQueueManager/
                     queue.manager.1")
            , IID_IADsContainer
            , (void **)&pADsContainer);
 
//
// Build an enumerator object for the specified Active Directory container
//
 
ADsBuildEnumerator(pADsContainer, &pEnumVariant);
 
while (fContinue)
{
    BSTR bstrClass = NULL;
    BSTR bstrName = NULL;
    IADs *pObject;
 
    //
    // Populate VARIANT array with elements fetched from
    // the enumerator object
    //
 
    fContinue = ADsEnumerateNext( pEnumVariant
                                , MAX_ADS_ENUM
                                , VariantArray
                                , &pElementFetched);
 
    //
    // Step through the VARIANT obtaining a pointer to the IADs interface
    // on each object. Using this interface, extract the name and class
    // of the object, printing this information onto the screen.
    //
 
    for (i= 0; i < cElementFetched; i++ )
    {
        IDispatch *pDispatch = NULL;
        pDispatch=VariantArray[i].pdispVal;
        pDispatch->QueryInterface( IID_IADs
                                 , (VOID **)&pObject);
        pObject->Get_Name (&bstrName);
        pObject->get_Class(&bstrClass)
 
        printf("  %S(%S)\n", bstrName, bstrClass) ;
 
        pObject->Release();
        pDispatch->Release();
    }
 
    memset( VariantArray
          , 0
          , sizeof(VARIANT)*MAX_ADS_ENUM);
 
    dwObjects += cElementFetched;
}
 
printf("Total Number of Objects enumerated is %d\n", dwObjects);
 
if (pEnumVariant)
{
    pEnumVariant->Release();
}
 
if (pADsContainer)
{
    pADsContainer->Release();
}