tstVBoxAPIWin.cpp revision 6739cf90e4aa3b3344768b8da241802f80ff455c
42576743851c3c956ad7e867e74df1084c30d434vboxsync/* $Id$ */
42576743851c3c956ad7e867e74df1084c30d434vboxsync/** @file
42576743851c3c956ad7e867e74df1084c30d434vboxsync *
42576743851c3c956ad7e867e74df1084c30d434vboxsync * tstVBoxAPIWin - sample program to illustrate the VirtualBox
42576743851c3c956ad7e867e74df1084c30d434vboxsync * COM API for machine management on Windows.
42576743851c3c956ad7e867e74df1084c30d434vboxsync It only uses standard C/C++ and COM semantics,
42576743851c3c956ad7e867e74df1084c30d434vboxsync * no additional VBox classes/macros/helpers. To
42576743851c3c956ad7e867e74df1084c30d434vboxsync * make things even easier to follow, only the
42576743851c3c956ad7e867e74df1084c30d434vboxsync * standard Win32 API has been used. Typically,
42576743851c3c956ad7e867e74df1084c30d434vboxsync * C++ developers would make use of Microsoft's
42576743851c3c956ad7e867e74df1084c30d434vboxsync * ATL to ease development.
42576743851c3c956ad7e867e74df1084c30d434vboxsync */
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync/*
42576743851c3c956ad7e867e74df1084c30d434vboxsync * Copyright (C) 2006-2007 Oracle Corporation
42576743851c3c956ad7e867e74df1084c30d434vboxsync *
42576743851c3c956ad7e867e74df1084c30d434vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
42576743851c3c956ad7e867e74df1084c30d434vboxsync * available from http://www.virtualbox.org. This file is free software;
42576743851c3c956ad7e867e74df1084c30d434vboxsync * you can redistribute it and/or modify it under the terms of the GNU
42576743851c3c956ad7e867e74df1084c30d434vboxsync * General Public License (GPL) as published by the Free Software
42576743851c3c956ad7e867e74df1084c30d434vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
42576743851c3c956ad7e867e74df1084c30d434vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
42576743851c3c956ad7e867e74df1084c30d434vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
42576743851c3c956ad7e867e74df1084c30d434vboxsync */
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync/*
42576743851c3c956ad7e867e74df1084c30d434vboxsync * PURPOSE OF THIS SAMPLE PROGRAM
42576743851c3c956ad7e867e74df1084c30d434vboxsync * ------------------------------
42576743851c3c956ad7e867e74df1084c30d434vboxsync *
42576743851c3c956ad7e867e74df1084c30d434vboxsync * This sample program is intended to demonstrate the minimal code necessary
42576743851c3c956ad7e867e74df1084c30d434vboxsync * to use VirtualBox COM API for learning puroses only. The program uses pure
42576743851c3c956ad7e867e74df1084c30d434vboxsync * Win32 API and doesn't have any extra dependencies to let you better
42576743851c3c956ad7e867e74df1084c30d434vboxsync * understand what is going on when a client talks to the VirtualBox core
42576743851c3c956ad7e867e74df1084c30d434vboxsync * using the COM framework.
6998b7cea7c904f33047cd17b05bea760a5839a9vboxsync *
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync * However, if you want to write a real application, it is highly recommended
42576743851c3c956ad7e867e74df1084c30d434vboxsync * to use our MS COM XPCOM Glue library and helper C++ classes. This way, you
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * will get at least the following benefits:
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync *
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * a) better portability: both the MS COM (used on Windows) and XPCOM (used
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync * everywhere else) VirtualBox client application from the same source code
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync * (including common smart C++ templates for automatic interface pointer
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync * reference counter and string data management);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync * b) simpler XPCOM initialization and shutdown (only a signle method call
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * that does everything right).
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync *
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync * Currently, there is no separate sample program that uses the VirtualBox MS
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * COM XPCOM Glue library. Please refer to the sources of stock VirtualBox
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * applications such as the VirtualBox GUI frontend or the VBoxManage command
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync * line frontend.
42576743851c3c956ad7e867e74df1084c30d434vboxsync */
42576743851c3c956ad7e867e74df1084c30d434vboxsync
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync#include <stdio.h>
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync#include "VirtualBox.h"
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync#define SAFE_RELEASE(x) \
43d42414bba4afb4e2aa2565d9278a3194f09304vboxsync if (x) { \
43d42414bba4afb4e2aa2565d9278a3194f09304vboxsync x->Release(); \
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync x = NULL; \
43d42414bba4afb4e2aa2565d9278a3194f09304vboxsync }
43d42414bba4afb4e2aa2565d9278a3194f09304vboxsync
43d42414bba4afb4e2aa2565d9278a3194f09304vboxsyncint listVMs(IVirtualBox *virtualBox)
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync{
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync HRESULT rc;
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /*
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync * First we have to get a list of all registered VMs
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync SAFEARRAY *machinesArray = NULL;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync rc = virtualBox->get_Machines(&machinesArray);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync if (SUCCEEDED(rc))
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IMachine **machines;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync rc = SafeArrayAccessData (machinesArray, (void **) &machines);
42576743851c3c956ad7e867e74df1084c30d434vboxsync if (SUCCEEDED(rc))
1379dfd407ada5fab15655776896f13b61a951fdvboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync for (ULONG i = 0; i < machinesArray->rgsabound[0].cElements; ++i)
1379dfd407ada5fab15655776896f13b61a951fdvboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync BSTR str;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync rc = machines[i]->get_Name(&str);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync if (SUCCEEDED(rc))
1379dfd407ada5fab15655776896f13b61a951fdvboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync printf("Name: %S\n", str);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SysFreeString(str);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync SafeArrayUnaccessData (machinesArray);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync SafeArrayDestroy (machinesArray);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync return 0;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync}
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsyncint testErrorInfo(IVirtualBox *virtualBox)
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync{
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync HRESULT rc;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Try to find a machine that doesn't exist */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IMachine *machine = NULL;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync BSTR machineName = SysAllocString(L"Foobar");
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync rc = virtualBox->FindMachine(machineName, &machine);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync if (FAILED(rc))
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync IErrorInfo *errorInfo;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync rc = GetErrorInfo(0, &errorInfo);
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync if (FAILED(rc))
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync printf("Error getting error info! rc = 0x%x\n", rc);
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync else
1379dfd407ada5fab15655776896f13b61a951fdvboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync BSTR errorDescription = NULL;
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync rc = errorInfo->GetDescription(&errorDescription);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync if (FAILED(rc) || !errorDescription)
1379dfd407ada5fab15655776896f13b61a951fdvboxsync printf("Error getting error description! rc = 0x%x\n", rc);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync else
1379dfd407ada5fab15655776896f13b61a951fdvboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync printf("Successfully retrieved error description: %S\n", errorDescription);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync SysFreeString(errorDescription);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync errorInfo->Release();
1379dfd407ada5fab15655776896f13b61a951fdvboxsync }
1379dfd407ada5fab15655776896f13b61a951fdvboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SAFE_RELEASE(machine);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SysFreeString(machineName);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync return 0;
1379dfd407ada5fab15655776896f13b61a951fdvboxsync}
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsyncint testStartVM(IVirtualBox *virtualBox)
1379dfd407ada5fab15655776896f13b61a951fdvboxsync{
1379dfd407ada5fab15655776896f13b61a951fdvboxsync HRESULT rc;
42576743851c3c956ad7e867e74df1084c30d434vboxsync
cb70b5cc08e3b666361766188f99cc86ed1626fbvboxsync /* Try to start a VM called "WinXP SP2". */
cb70b5cc08e3b666361766188f99cc86ed1626fbvboxsync IMachine *machine = NULL;
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync BSTR machineName = SysAllocString(L"WinXP SP2");
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync rc = virtualBox->FindMachine(machineName, &machine);
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync if (FAILED(rc))
42576743851c3c956ad7e867e74df1084c30d434vboxsync {
42576743851c3c956ad7e867e74df1084c30d434vboxsync IErrorInfo *errorInfo;
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync rc = GetErrorInfo(0, &errorInfo);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync if (FAILED(rc))
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync printf("Error getting error info! rc = 0x%x\n", rc);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync else
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync {
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync BSTR errorDescription = NULL;
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync rc = errorInfo->GetDescription(&errorDescription);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync if (FAILED(rc) || !errorDescription)
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync printf("Error getting error description! rc = 0x%x\n", rc);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync else
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync {
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync printf("Successfully retrieved error description: %S\n", errorDescription);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync SysFreeString(errorDescription);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync }
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SAFE_RELEASE(errorInfo);
e80aaa9a63f82ac2cece3a2d5a415774a72b0c82vboxsync }
42576743851c3c956ad7e867e74df1084c30d434vboxsync }
2d0371c5f4b5bf0651da37a13cd3ae7479dd0432vboxsync else
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync ISession *session = NULL;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IConsole *console = NULL;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IProgress *progress = NULL;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync BSTR sessiontype = SysAllocString(L"gui");
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync BSTR guid;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync do
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync rc = machine->get_Id(&guid); /* Get the GUID of the machine. */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync if (!SUCCEEDED(rc))
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync printf("Error retrieving machine ID! rc = 0x%x\n", rc);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync break;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Create the session object. */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync rc = CoCreateInstance(CLSID_Session, /* the VirtualBox base object */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync NULL, /* no aggregation */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync CLSCTX_INPROC_SERVER, /* the object lives in a server process on this machine */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IID_ISession, /* IID of the interface */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync (void**)&session);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync if (!SUCCEEDED(rc))
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync printf("Error creating Session instance! rc = 0x%x\n", rc);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync break;
1379dfd407ada5fab15655776896f13b61a951fdvboxsync }
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync /* Start a VM session using the delivered VBox GUI. */
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync rc = virtualBox->OpenRemoteSession (session, guid, sessiontype,
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync NULL, &progress);
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync if (!SUCCEEDED(rc))
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync {
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync printf("Could not open remote session! rc = 0x%x\n", rc);
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync break;
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync }
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /* Wait until VM is running. */
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync printf ("Starting VM, please wait ...\n");
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync rc = progress->WaitForCompletion (-1);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /* Get console object. */
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync session->get_Console(&console);
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /* Bring console window to front. */
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync machine->ShowConsoleWindow(0);
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync printf ("Press enter to power off VM and close the session...\n");
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync getchar();
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /* Power down the machine. */
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync rc = console->PowerDown(&progress);
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync /* Wait until VM is powered down. */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync printf ("Powering off VM, please wait ...\n");
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync rc = progress->WaitForCompletion (-1);
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Close the session. */
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync rc = session->Close();
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync } while (0);
e70bda5438c3582164d26f171a8bc8d3d7da1e12vboxsync
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SAFE_RELEASE(console);
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync SAFE_RELEASE(progress);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SAFE_RELEASE(session);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SysFreeString(guid);
1379dfd407ada5fab15655776896f13b61a951fdvboxsync SysFreeString(sessiontype);
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync SAFE_RELEASE(machine);
42576743851c3c956ad7e867e74df1084c30d434vboxsync }
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync SysFreeString(machineName);
42576743851c3c956ad7e867e74df1084c30d434vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync return 0;
42576743851c3c956ad7e867e74df1084c30d434vboxsync}
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsyncint main(int argc, char *argv[])
e89bf42607ac3c1b6c60fabbf6067a38adb1284bvboxsync{
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync HRESULT rc;
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync IVirtualBox *virtualBox;
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync do
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync {
1379dfd407ada5fab15655776896f13b61a951fdvboxsync /* Initialize the COM subsystem. */
b32be08cd134577ca98e517c019c867c416ec0f2vboxsync CoInitialize(NULL);
b32be08cd134577ca98e517c019c867c416ec0f2vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Instantiate the VirtualBox root object. */
f4d2071f8959189ae2c0c2faa4d2944ee37523d9vboxsync rc = CoCreateInstance(CLSID_VirtualBox, /* the VirtualBox base object */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync NULL, /* no aggregation */
f4d2071f8959189ae2c0c2faa4d2944ee37523d9vboxsync CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync IID_IVirtualBox, /* IID of the interface */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync (void**)&virtualBox);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync if (!SUCCEEDED(rc))
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync {
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync printf("Error creating VirtualBox instance! rc = 0x%x\n", rc);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync break;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync }
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync listVMs(virtualBox);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync testErrorInfo(virtualBox);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Enable the following line to get a VM started. */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync //testStartVM(virtualBox);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync /* Release the VirtualBox object. */
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync virtualBox->Release();
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync } while (0);
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync CoUninitialize();
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync return 0;
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync}
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync
2d66abeefb9716ed570bb5714884d3fe08629452vboxsync