tstVBoxAPIWin.cpp revision df2e37f58f19997178bb9be53867a17509a3a2f9
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** @file
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * tstVBoxAPIWin - sample program to illustrate the VirtualBox
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * COM API for machine management on Windows.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync It only uses standard C/C++ and COM semantics,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * no additional VBox classes/macros/helpers. To
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync * make things even easier to follow, only the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * standard Win32 API has been used. Typically,
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * C++ developers would make use of Microsoft's
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * ATL to ease development.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * available from http://www.virtualbox.org. This file is free software;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * General Public License (GPL) as published by the Free Software
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * additional information or have any questions.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * PURPOSE OF THIS SAMPLE PROGRAM
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * ------------------------------
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This sample program is intended to demonstrate the minimal code necessary
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * to use VirtualBox COM API for learning puroses only. The program uses pure
628ddfbd43ad5365d69fddda4007598242956577vboxsync * Win32 API and doesn't have any extra dependencies to let you better
628ddfbd43ad5365d69fddda4007598242956577vboxsync * understand what is going on when a client talks to the VirtualBox core
628ddfbd43ad5365d69fddda4007598242956577vboxsync * using the COM framework.
628ddfbd43ad5365d69fddda4007598242956577vboxsync *
628ddfbd43ad5365d69fddda4007598242956577vboxsync * However, if you want to write a real application, it is highly recommended
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * to use our MS COM XPCOM Glue library and helper C++ classes. This way, you
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * will get at least the following benefits:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync * a) better portability: both the MS COM (used on Windows) and XPCOM (used
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync * everywhere else) VirtualBox client application from the same source code
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync * (including common smart C++ templates for automatic interface pointer
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * reference counter and string data management);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * b) simpler XPCOM initialization and shutdown (only a signle method call
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * that does everything right).
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Currently, there is no separate sample program that uses the VirtualBox MS
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync * COM XPCOM Glue library. Please refer to the sources of stock VirtualBox
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * applications such as the VirtualBox GUI frontend or the VBoxManage command
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * line frontend.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <stdio.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include "VirtualBox.h"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define SAFE_RELEASE(x) \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (x) { \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync x->Release(); \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync x = NULL; \
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncint listVMs(IVirtualBox *virtualBox)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT rc;
2f0d866e126dd288169fed591c259c1c6b4016e5vboxsync
ae5379e3e7573369566d4628ef6c597da693cc55vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * First we have to get a list of all registered VMs
9fbcdff887bd2d679720a8a50f5601df57b32b1bvboxsync */
ae5379e3e7573369566d4628ef6c597da693cc55vboxsync SAFEARRAY *machinesArray = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = virtualBox->get_Machines(&machinesArray);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (SUCCEEDED(rc))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync IMachine **machines;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = SafeArrayAccessData (machinesArray, (void **) &machines);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync for (ULONG i = 0; i < machinesArray->rgsabound[0].cElements; ++i)
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync {
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync BSTR str;
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync
37e7010b28a4667800196960b59cd63b5434b7d7vboxsync rc = machines[i]->get_Name(&str);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (SUCCEEDED(rc))
400d70dc1edb0f6d2a9d3a860b1b43f0b2cdfb39vboxsync {
b6247ebeef75e5ab689ba845ad8cae8746607bb3vboxsync printf("Name: %S\n", str);
400d70dc1edb0f6d2a9d3a860b1b43f0b2cdfb39vboxsync SysFreeString(str);
400d70dc1edb0f6d2a9d3a860b1b43f0b2cdfb39vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync SafeArrayUnaccessData (machinesArray);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync SafeArrayDestroy (machinesArray);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncint testErrorInfo(IVirtualBox *virtualBox)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT rc;
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Try to find a machine that doesn't exist */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync IMachine *machine = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync BSTR machineName = SysAllocString(L"Foobar");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = virtualBox->FindMachine(machineName, &machine);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync IErrorInfo *errorInfo;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = GetErrorInfo(0, &errorInfo);
ce5210fe822f74de78c3dddc74f32a2cabcee5fdvboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (FAILED(rc))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync printf("Error getting error info! rc = 0x%x\n", rc);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else
ce5210fe822f74de78c3dddc74f32a2cabcee5fdvboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync BSTR errorDescription = NULL;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync rc = errorInfo->GetDescription(&errorDescription);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
77cce7691847be5aef145f31ba3f9d66fc2cf594vboxsync if (FAILED(rc) || !errorDescription)
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync printf("Error getting error description! rc = 0x%x\n", rc);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync else
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync printf("Successfully retrieved error description: %S\n", errorDescription);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync SysFreeString(errorDescription);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync errorInfo->Release();
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync SAFE_RELEASE(machine);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync SysFreeString(machineName);
9e293277b378073ce86910209a246b744b4caa2cvboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync return 0;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync}
9e293277b378073ce86910209a246b744b4caa2cvboxsync
aabfd650b7e36e2c25a6d48b2a2bfd95fe93b65avboxsync
aabfd650b7e36e2c25a6d48b2a2bfd95fe93b65avboxsyncint testStartVM(IVirtualBox *virtualBox)
aabfd650b7e36e2c25a6d48b2a2bfd95fe93b65avboxsync{
9e293277b378073ce86910209a246b744b4caa2cvboxsync HRESULT rc;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync /* Try to start a VM called "WinXP SP2". */
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync IMachine *machine = NULL;
bdd15592ca3578b623ff588055a561f58b7e5586vboxsync BSTR machineName = SysAllocString(L"WinXP SP2");
9e293277b378073ce86910209a246b744b4caa2cvboxsync
7f5e9cb0292dcce87c0a6794c775c14fb9c2a1e7vboxsync rc = virtualBox->FindMachine(machineName, &machine);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync if (FAILED(rc))
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync IErrorInfo *errorInfo;
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync rc = GetErrorInfo(0, &errorInfo);
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync if (FAILED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf("Error getting error info! rc = 0x%x\n", rc);
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync else
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync BSTR errorDescription = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = errorInfo->GetDescription(&errorDescription);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (FAILED(rc) || !errorDescription)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf("Error getting error description! rc = 0x%x\n", rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
f350b7cf96f1e2f3b0cfd34cfe8726c754f43584vboxsync {
551d9b8ee3568ad3e11b65ce6ef2867c36375f37vboxsync printf("Successfully retrieved error description: %S\n", errorDescription);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync SysFreeString(errorDescription);
b8908d384db2324f04a2f68a13e67ea32ebf609avboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SAFE_RELEASE(errorInfo);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync }
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync else
b603b2af577731f9f825ba3681cd5b728bb1d1d4vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ISession *session = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync IConsole *console = NULL;
8e0c2ca3abd721979958f95b9af73b60665478c8vboxsync IProgress *progress = NULL;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync BSTR sessiontype = SysAllocString(L"gui");
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync BSTR guid;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync do
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = machine->get_Id(&guid); /* Get the GUID of the machine. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!SUCCEEDED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync printf("Error retrieving machine ID! rc = 0x%x\n", rc);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Create the session object. */
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync rc = CoCreateInstance(CLSID_Session, /* the VirtualBox base object */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync NULL, /* no aggregation */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync CLSCTX_INPROC_SERVER, /* the object lives in a server process on this machine */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync IID_ISession, /* IID of the interface */
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync (void**)&session);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!SUCCEEDED(rc))
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync {
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync printf("Error creating Session instance! rc = 0x%x\n", rc);
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync break;
3ca89d9d8c4fc158ba28bdf82c9cc3697625ce12vboxsync }
39592d8ff3243f6116c4e99be391bcf30a4ad187vboxsync
6f6e182fde44ac8c4f95d8684e10fbbea937f26evboxsync /* Start a VM session using the delivered VBox GUI. */
6f6e182fde44ac8c4f95d8684e10fbbea937f26evboxsync rc = virtualBox->OpenRemoteSession (session, guid, sessiontype,
20fc4a350a4a8e56ffaac6cf57dcd677a7ac36c5vboxsync NULL, &progress);
20fc4a350a4a8e56ffaac6cf57dcd677a7ac36c5vboxsync if (!SUCCEEDED(rc))
6f6e182fde44ac8c4f95d8684e10fbbea937f26evboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf("Could not open remote session! rc = 0x%x\n", rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Wait until VM is running. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf ("Starting VM, please wait ...\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = progress->WaitForCompletion (-1);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Get console object. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync session->get_Console(&console);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync /* Bring console window to front. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync machine->ShowConsoleWindow(0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf ("Press enter to power off VM and close the session...\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync getchar();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Power down the machine. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = console->PowerDown();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Close the session. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = session->Close();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync } while (0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SAFE_RELEASE(console);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SAFE_RELEASE(progress);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SAFE_RELEASE(session);
c77e7bff89c7639353778366984d51ff165ea0e3vboxsync SysFreeString(guid);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SysFreeString(sessiontype);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SAFE_RELEASE(machine);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SysFreeString(machineName);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncint main(int argc, char *argv[])
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HRESULT rc;
f14d3c62ebf4ccb64bd11528e5c4ec60b4528a1avboxsync IVirtualBox *virtualBox;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync do
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Initialize the COM subsystem. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync CoInitialize(NULL);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Instantiate the VirtualBox root object. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = CoCreateInstance(CLSID_VirtualBox, /* the VirtualBox base object */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync NULL, /* no aggregation */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync IID_IVirtualBox, /* IID of the interface */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync (void**)&virtualBox);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!SUCCEEDED(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync printf("Error creating VirtualBox instance! rc = 0x%x\n", rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync listVMs(virtualBox);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync testErrorInfo(virtualBox);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Enable the following line to get a VM started. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync //testStartVM(virtualBox);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release the VirtualBox object. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync virtualBox->Release();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync } while (0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync CoUninitialize();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync