VirtualBox

Changeset 7389 in vbox


Ignore:
Timestamp:
Mar 9, 2008 11:56:51 PM (17 years ago)
Author:
vboxsync
Message:

Main/tstVBoxAPIWin: Updated to use arrays instead of collections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/tstVBoxAPIWin.cpp

    r5999 r7389  
    6262     * First we have to get a list of all registered VMs
    6363     */
    64     IMachineCollection *collection = NULL;
    65     IMachineEnumerator *enumerator = NULL;
     64    SAFEARRAY *machinesArray = NULL;
    6665
    67     do
     66    rc = virtualBox->get_Machines2(&machinesArray);
     67    if (SUCCEEDED(rc))
    6868    {
    69         rc = virtualBox->get_Machines(&collection);
    70         if (SUCCEEDED(rc))
    71             rc = collection->Enumerate(&enumerator);
    72 
     69        IMachine **machines;
     70        rc = SafeArrayAccessData (machinesArray, (void **) &machines);
    7371        if (SUCCEEDED(rc))
    7472        {
    75             BOOL hasMore;
    76             while (enumerator->HasMore(&hasMore), hasMore)
     73            for (ULONG i = 0; i < machinesArray->rgsabound[0].cElements; ++i)
    7774            {
    78                 /*
    79                  * Get the machine object
    80                  */
    81                 IMachine *machine = NULL;
    82                 rc = enumerator->GetNext(&machine);
     75                BSTR str;
     76
     77                rc = machines[i]->get_Name(&str);
    8378                if (SUCCEEDED(rc))
    8479                {
    85                     BSTR str;
    86 
    87                     machine->get_Name(&str);
    8880                    printf("Name: %S\n", str);
    89 
    9081                    SysFreeString(str);
    91 
    92                     machine->Release();
    9382                }
    9483            }
     84
     85            SafeArrayUnaccessData (machinesArray);
    9586        }
    96     } while (0);
    9787
    98     if (enumerator)
    99         enumerator->Release();
    100     if (collection)
    101         collection->Release();
     88        SafeArrayDestroy (machinesArray);
     89    }
    10290
    10391    return 0;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette