tstVBoxAPIWin.cpp revision f1daaa0616e682b0e714481387d01d8d417a00d1
/** @file
*
* tstVBoxAPIWin - sample program to illustrate the VirtualBox
* COM API for machine management on Windows.
It only uses standard C/C++ and COM semantics,
* make things even easier to follow, only the
* standard Win32 API has been used. Typically,
* C++ developers would make use of Microsoft's
* ATL to ease development.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* PURPOSE OF THIS SAMPLE PROGRAM
* ------------------------------
*
* This sample program is intended to demonstrate the minimal code necessary
* to use VirtualBox COM API for learning puroses only. The program uses pure
* Win32 API and doesn't have any extra dependencies to let you better
* understand what is going on when a client talks to the VirtualBox core
* using the COM framework.
*
* However, if you want to write a real application, it is highly recommended
* to use our MS COM XPCOM Glue library and helper C++ classes. This way, you
* will get at least the following benefits:
*
* a) better portability: both the MS COM (used on Windows) and XPCOM (used
* everywhere else) VirtualBox client application from the same source code
* (including common smart C++ templates for automatic interface pointer
* reference counter and string data management);
* b) simpler XPCOM initialization and shutdown (only a signle method call
* that does everything right).
*
* Currently, there is no separate sample program that uses the VirtualBox MS
* COM XPCOM Glue library. Please refer to the sources of stock VirtualBox
* applications such as the VirtualBox GUI frontend or the VBoxManage command
* line frontend.
*/
#include <stdio.h>
#include "VirtualBox.h"
{
/*
* First we have to get a list of all registered VMs
*/
{
{
{
{
}
}
}
}
return 0;
}
{
/* try to find a machine that doesn't exist */
{
else
{
else
{
}
}
}
if (machine)
return 0;
}
{
do
{
/* initialize the COM subsystem */
/* instantiate the VirtualBox root object */
NULL, /* no aggregation */
CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */
IID_IVirtualBox, /* IID of the interface */
(void**)&virtualBox);
{
break;
}
/* release the VirtualBox object */
virtualBox->Release();
} while (0);
return 0;
}