tstAPI.cpp revision d66d6bff1611bf92fac8724b3fc548f78a6f8d71
7df95d48add893eab9003d793e18c099e126edf9vboxsync/** @file
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync *
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * tstAPI - test program for our COM/XPCOM interface
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync */
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync/*
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * available from http://www.virtualbox.org. This file is free software;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * General Public License as published by the Free Software Foundation,
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * If you received this file as part of a commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * distribution, then only the terms of your commercial VirtualBox
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * license agreement apply instead of the previous paragraph.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync */
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <stdio.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <stdlib.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/com.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/string.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/Guid.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/ErrorInfo.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/EventQueue.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/com/VirtualBox.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsyncusing namespace com;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#define LOG_ENABLED
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#define LOG_GROUP LOG_GROUP_MAIN
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#define LOG_INSTANCE NULL
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#include <VBox/log.h>
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync#include <iprt/runtime.h>
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#include <iprt/stream.h>
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync#define printf RTPrintf
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync// funcs
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync///////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsyncHRESULT readAndChangeMachineSettings (IMachine *machine, IMachine *readonlyMachine = 0)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync{
3b9591b897f4b581f0be311535f93fd3a555c576vboxsync HRESULT rc = S_OK;
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync Bstr name;
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Getting machine name...\n");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_RET (machine->COMGETTER(Name) (name.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Name: {%ls}\n", name.raw());
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync
fb34b57e69a76bea498e3a3b9adebe1d526d7f78vboxsync printf("Getting machine GUID...\n");
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync Guid guid;
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync CHECK_RC (machine->COMGETTER(Id) (guid.asOutParam()));
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync if (SUCCEEDED (rc) && !guid.isEmpty()) {
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("Guid::toString(): {%s}\n", (const char *) guid.toString());
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync } else {
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("WARNING: there's no GUID!");
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync }
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync ULONG memorySize;
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync printf ("Getting memory size...\n");
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySize));
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("Memory size: %d\n", memorySize);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync MachineState_T machineState;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting machine state...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(State) (&machineState));
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync printf ("Machine state: %d\n", machineState);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync BOOL modified;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Are any settings modified?...\n");
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC (machine->COMGETTER(SettingsModified) (&modified));
a9e040e11af94d3457b824f2942d11375f16f598vboxsync if (SUCCEEDED (rc))
a9e040e11af94d3457b824f2942d11375f16f598vboxsync printf ("%s\n", modified ? "yes" : "no");
a9e040e11af94d3457b824f2942d11375f16f598vboxsync
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync ULONG memorySizeBig = memorySize * 10;
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf("Changing memory size to %d...\n", memorySizeBig);
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC (machine->COMSETTER(MemorySize) (memorySizeBig));
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync if (SUCCEEDED (rc)) {
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf ("Are any settings modified now?...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("%s\n", modified ? "yes" : "no");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ASSERT_RET (modified, 0);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ULONG memorySizeGot;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting memory size again...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Memory size: %d\n", memorySizeGot);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ASSERT_RET (memorySizeGot == memorySizeBig, 0);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (readonlyMachine) {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting memory size of the counterpart readonly machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ULONG memorySizeRO;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Memory size: %d\n", memorySizeRO);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ASSERT_RET (memorySizeRO != memorySizeGot, 0);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
9f9f83ee5948916d644046a79836873db40bfc88vboxsync
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Discarding recent changes...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_RET (machine->DiscardSettings());
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync printf ("Are any settings modified after discarding?...\n");
4a61dadcdd5fbace94426335d7a985ff31936a2cvboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("%s\n", modified ? "yes" : "no");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ASSERT_RET (!modified, 0);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting memory size once more...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->COMGETTER(MemorySize) (&memorySizeGot));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Memory size: %d\n", memorySizeGot);
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync ASSERT_RET (memorySizeGot == memorySize, 0);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf("Changing memory size to %d...\n", memorySize);
a9e040e11af94d3457b824f2942d11375f16f598vboxsync CHECK_RC_RET (machine->COMSETTER(MemorySize) (memorySize));
a9e040e11af94d3457b824f2942d11375f16f598vboxsync }
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf ("Saving machine settings...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC (machine->SaveSettings());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync if (SUCCEEDED (rc)) {
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Are any settings modified after saving?...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_RET (machine->COMGETTER(SettingsModified) (&modified));
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync printf ("%s\n", modified ? "yes" : "no");
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync ASSERT_RET (!modified, 0);
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync if (readonlyMachine) {
6a713fdf2e42488a1179d8c5a9d9cc62e484b1f0vboxsync printf ("Getting memory size of the counterpart readonly machine...\n");
c808a168c13130bbd814115581cd91e6fe28472bvboxsync ULONG memorySizeRO;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync readonlyMachine->COMGETTER(MemorySize) (&memorySizeRO);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Memory size: %d\n", memorySizeRO);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ASSERT_RET (memorySizeRO == memorySize, 0);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
9f9f83ee5948916d644046a79836873db40bfc88vboxsync
9f9f83ee5948916d644046a79836873db40bfc88vboxsync Bstr extraDataKey = L"Blafasel";
9f9f83ee5948916d644046a79836873db40bfc88vboxsync Bstr extraData;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Getting extra data key {%ls}...\n", extraDataKey.raw());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
9f9f83ee5948916d644046a79836873db40bfc88vboxsync if (!extraData.isEmpty()) {
9f9f83ee5948916d644046a79836873db40bfc88vboxsync printf ("Extra data value: {%ls}\n", extraData.raw());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync } else {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (extraData.isNull())
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("No extra data exists\n");
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync else
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("Extra data is empty\n");
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (extraData.isEmpty())
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync extraData = L"Das ist die Berliner Luft, Luft, Luft...";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync else
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync extraData.setNull();
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf (
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync "Setting extra data key {%ls} to {%ls}...\n",
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync extraDataKey.raw(), extraData.raw()
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync );
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC (machine->SetExtraData (extraDataKey, extraData));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (SUCCEEDED (rc)) {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting extra data key {%ls} again...\n", extraDataKey.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (machine->GetExtraData (extraDataKey, extraData.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (!extraData.isEmpty()) {
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Extra data value: {%ls}\n", extraData.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync } else {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (extraData.isNull())
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("No extra data exists\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Extra data is empty\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync return rc;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync}
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// main
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync///////////////////////////////////////////////////////////////////////////////
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsyncint main(int argc, char *argv[])
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync{
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync /*
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * Initialize the VBox runtime without loading
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync * the support driver.
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync */
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTR3Init(false);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync HRESULT rc;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Initializing COM...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_RET (com::Initialize());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // scopes all the stuff till shutdown
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IVirtualBox> virtualBox;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <ISession> session;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("Creating VirtualBox object...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox,
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync "VirtualBoxServer"));
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync if (FAILED (rc))
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync {
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_ERROR_NOCALL();
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync break;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync }
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("Creating Session object...\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC (session.createInprocObject (CLSID_Session));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync if (FAILED (rc))
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
cb130fe54ffed3568729e3546b9aa73190e1c1advboxsync CHECK_ERROR_NOCALL();
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync break;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync }
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync#if 0
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync // IUnknown identity test
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync ////////////////////////////////////////////////////////////////////////////
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync {
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync ComPtr <IVirtualBox> virtualBox2;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("Creating one more VirtualBox object...\n");
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox,
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync "VirtualBoxServer"));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync if (FAILED (rc))
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_NOCALL();
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync break;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync printf ("IVirtualBox(virualBox)=%p IVirtualBox(virualBox2)=%p\n",
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync (IVirtualBox *) virtualBox, (IVirtualBox *) virtualBox2);
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IUnknown> unk (virtualBox);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ComPtr <IUnknown> unk2;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync unk2 = virtualBox2;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("IUnknown(virualBox)=%p IUnknown(virualBox2)=%p\n",
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync (IUnknown *) unk, (IUnknown *) unk2);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ComPtr <IVirtualBox> vb = unk;
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync ComPtr <IVirtualBox> vb2 = unk;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("IVirtualBox(IUnknown(virualBox))=%p IVirtualBox(IUnknown(virualBox2))=%p\n",
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync (IVirtualBox *) vb, (IVirtualBox *) vb2);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Will be now released (press Enter)...");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync getchar();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // create the event queue
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // (here it is necessary only to process remaining XPCOM/IPC events
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // after the session is closed)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync EventQueue eventQ;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // some outdated stuff
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Getting IHost interface...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHost *host;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = virtualBox->GetHost(&host);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (SUCCEEDED(rc))
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostDVDDriveCollection *dvdColl;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = host->GetHostDVDDrives(&dvdColl);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (SUCCEEDED(rc))
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostDVDDrive *dvdDrive = NULL;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (dvdDrive)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync BSTR driveName;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync char *driveNameUtf8;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdDrive->GetDriveName(&driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Host DVD drive name: %s\n", driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrFree(driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync SysFreeString(driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostDVDDrive *dvdDriveTemp = dvdDrive;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdDriveTemp->Release();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync dvdColl->Release();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync } else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Could not get host DVD drive collection\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostFloppyDriveCollection *floppyColl;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = host->GetHostFloppyDrives(&floppyColl);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (SUCCEEDED(rc))
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostFloppyDrive *floppyDrive = NULL;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (floppyDrive)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync BSTR driveName;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync char *driveNameUtf8;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyDrive->GetDriveName(&driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrUcs2ToUtf8(&driveNameUtf8, (PCRTUCS2)driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Host floppy drive name: %s\n", driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTStrFree(driveNameUtf8);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync SysFreeString(driveName);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync IHostFloppyDrive *floppyDriveTemp = floppyDrive;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyDriveTemp->Release();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync floppyColl->Release();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync } else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Could not get host floppy drive collection\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync host->Release();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync } else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf("Call failed\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // IVirtualBoxErrorInfo test
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ////////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // RPC calls
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely fail
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Guid uuid;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IHardDisk> hardDisk;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely succeed
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr version;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = virtualBox->COMGETTER(Version) (version.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("virtualBox->COMGETTER(Version)=%08X\n", rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // Local calls
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely fail
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IMachine> machine;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = session->COMGETTER(Machine)(machine.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("session->COMGETTER(Machine)=%08X\n", rc);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
dcba8de9fb9216170ee6740b57a51b3c8f2a55fcvboxsync// {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // call a method that will definitely succeed
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync SessionState_T state;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync rc = session->COMGETTER(State) (&state);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("session->COMGETTER(State)=%08X\n", rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync com::ErrorInfo info (virtualBox);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync PRINT_ERROR_INFO (info);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // register the existing hard disk image
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IHardDisk> hd;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Registerin the existing hard disk '%ls'...\n", src.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, OpenHardDisk (src, hd.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, RegisterHardDisk (hd));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // find and unregister the existing hard disk image
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IVirtualDiskImage> vdi;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"CreatorTest.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Unregistering the hard disk '%ls'...\n", src.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IHardDisk> hd = vdi;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Guid id;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, UnregisterHardDisk (id, hd.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // clone the registered hard disk
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if defined __LINUX__
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr src = L"E:/develop/innotek/images/freedos.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr dst = L"./clone.vdi";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTPrintf ("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IVirtualDiskImage> vdi;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindVirtualDiskImage (src, vdi.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IHardDisk> hd = vdi;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IProgress> progress;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (hd, CloneToImage (dst, vdi.asOutParam(), progress.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTPrintf ("Waiting for completion...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ProgressErrorInfo ei (progress);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync if (FAILED (ei.getResultCode()))
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync PRINT_ERROR_INFO (ei);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync vdi->COMGETTER(FilePath) (dst.asOutParam());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // access the machine in read-only mode
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IMachine> machine;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr name = "Windows XP";
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// printf ("Accessing the machine in read-only mode:\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// readAndChangeMachineSettings (machine);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync// if (argc != 2)
dcba8de9fb9216170ee6740b57a51b3c8f2a55fcvboxsync// {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// printf("Error: a string has to be supplied!\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// else
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// Bstr secureLabel = argv[1];
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// machine->COMSETTER(ExtraData)(L"VBoxSDL/SecureLabel", secureLabel);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync// }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 1
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // create a new machine (w/o registering it)
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IMachine> m;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync do
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync {
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ComPtr <IMachine> machine;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#if defined (__LINUX__)
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr baseDir = L"/tmp/vbox";
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#else
a9e040e11af94d3457b824f2942d11375f16f598vboxsync Bstr baseDir = L"C:\\vbox";
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync#endif
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync Bstr name = L"machina";
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync printf ("Creating a new machine object (base dir '%ls', name '%ls')...\n",
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync baseDir.raw(), name.raw());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (virtualBox, CreateMachine (baseDir, name,
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync machine.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting name...\n");
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_ERROR_BREAK (machine, COMGETTER(Name) (name.asOutParam()));
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync printf ("Name: {%ls}\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync BOOL modified = FALSE;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Are any settings modified?...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (machine, COMGETTER(SettingsModified) (&modified));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("%s\n", modified ? "yes" : "no");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ASSERT_BREAK (modified == TRUE);
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync name = L"Kakaya prekrasnaya virtual'naya mashina!";
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Setting new name ({%ls})...\n", name.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (machine, COMSETTER(Name) (name));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Setting memory size to 111...\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (machine, COMSETTER(MemorySize) (111));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IGuestOSType> guestOSType;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Bstr type = L"os2warp45";
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (virtualBox, FindGuestOSType (type, guestOSType.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Saving new machine settings...\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR_BREAK (machine, SaveSettings());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Accessing the newly created machine:\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync readAndChangeMachineSettings (machine);
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsyncm = machine;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync }
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (FALSE);
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync printf ("\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync#endif
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync#if 0
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync // enumerate host DVD drives
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ///////////////////////////////////////////////////////////////////////////
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync do
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHost> host;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(Host) (host.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHostDVDDriveCollection> coll;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (host->COMGETTER(DVDDrives) (coll.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHostDVDDriveEnumerator> enumerator;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync BOOL hasmore;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHostDVDDrive> drive;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (enumerator->GetNext (drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Bstr name;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Host DVD drive: name={%ls}\n", name.raw());
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync }
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (rc);
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHostDVDDrive> drive;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (enumerator, GetNext (drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (coll, GetItemAt (1000, drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_ERROR (coll, FindByName (Bstr ("R:"), drive.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync if (SUCCEEDED (rc))
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Bstr name;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (drive->COMGETTER(Name) (name.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Found by name: name={%ls}\n", name.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync }
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync }
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync }
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (FALSE);
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync#endif
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync#if 0
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync // enumerate hard disks & dvd images
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ///////////////////////////////////////////////////////////////////////////
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync do
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHardDiskCollection> coll;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(HardDisks) (coll.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHardDiskEnumerator> enumerator;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync BOOL hasmore;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync {
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync ComPtr <IHardDisk> disk;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (enumerator->GetNext (disk.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Guid id;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (disk->COMGETTER(Id) (id.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Bstr path;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (disk->COMGETTER(FilePath) (path.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Hard Disk: id={%s}, path={%ls}\n",
a9e040e11af94d3457b824f2942d11375f16f598vboxsync id.toString().raw(), path.raw());
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Guid mid;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync virtualBox->GetHardDiskUsage (id, ResourceUsage_AllUsage,
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync mid.asOutParam())
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync );
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync if (mid.isEmpty())
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf (" not used\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync else
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf (" used by VM: {%s}\n", mid.toString().raw());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC_BREAK (rc);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync ComPtr <IDVDImageCollection> coll;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC_BREAK (virtualBox->COMGETTER(DVDImages) (coll.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IDVDImageEnumerator> enumerator;
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync CHECK_RC_BREAK (coll->Enumerate (enumerator.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync BOOL hasmore;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync while (SUCCEEDED (enumerator->HasMore (&hasmore)) && hasmore)
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync {
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ComPtr <IDVDImage> image;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (enumerator->GetNext (image.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync Guid id;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_RC_BREAK (image->COMGETTER(Id) (id.asOutParam()));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync Bstr path;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (image->COMGETTER(FilePath) (path.asOutParam()));
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync printf ("CD/DVD Image: id={%s}, path={%ls}\n",
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync id.toString().raw(), path.raw());
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync Bstr mIDs;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync virtualBox->GetDVDImageUsage (id, ResourceUsage_AllUsage,
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync mIDs.asOutParam())
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync );
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync if (mIDs.isNull())
b5523a351ce3a0829df2421672ef4bf1481970bcvboxsync printf (" not used\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync else
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync printf (" used by VMs: {%ls}\n", mIDs.raw());
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync }
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (rc);
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync }
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync while (FALSE);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#endif
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#if 0
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync // open a (direct) session
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync {
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync ComPtr <IMachine> machine;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr name = L"dos";
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_ERROR_BREAK (virtualBox, FindMachine (name, machine.asOutParam()));
fe813b3594039ba864493438e78ee0e7132bc445vboxsync Guid guid;
4e12eda9a6e918332bb14827546097d878ef8a2dvboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Opening a session for this machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->OpenSession (session, guid));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IMachine> sessionMachine;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Getting sessioned machine object...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Accessing the machine within the session:\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync readAndChangeMachineSettings (sessionMachine, machine);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#endif
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#if 0
b8939a8db837f27574e06c82474888bdd058ce17vboxsync ComPtr <IConsole> console;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Getting the console object...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Discarding the current machine state...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ComPtr <IProgress> progress;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (console, DiscardCurrentState (progress.asOutParam()));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Waiting for completion...\n");
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync CHECK_ERROR_BREAK (progress, WaitForCompletion (-1));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ProgressErrorInfo ei (progress);
b8939a8db837f27574e06c82474888bdd058ce17vboxsync if (FAILED (ei.getResultCode()))
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync {
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync PRINT_ERROR_INFO (ei);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ComPtr <IUnknown> initiator;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_ERROR_BREAK (progress, COMGETTER(Initiator) (initiator.asOutParam()));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("initiator(unk) = %p\n", (IUnknown *) initiator);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("console(unk) = %p\n", (IUnknown *) ComPtr <IUnknown> ((IConsole *) console));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("console = %p\n", (IConsole *) console);
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync }
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync session->Close();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#if 0
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync // open a remote session
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ///////////////////////////////////////////////////////////////////////////
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync do
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync {
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IMachine> machine;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync Bstr name = L"dos";
9f9f83ee5948916d644046a79836873db40bfc88vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync Guid guid;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Opening a remote session for this machine...\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync ComPtr <IProgress> progress;
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
ccc1001951ecd639b15b3034260c6012423349b3vboxsync progress.asOutParam()));
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("Waiting for the session to open...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (progress->WaitForCompletion (-1));
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync ComPtr <IMachine> sessionMachine;
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Getting sessioned machine object...\n");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
a9e040e11af94d3457b824f2942d11375f16f598vboxsync ComPtr <IConsole> console;
b5523a351ce3a0829df2421672ef4bf1481970bcvboxsync printf ("Getting console object...\n");
fdc1cae8a7a45e9299077dd0270c3736b02e4e97vboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to pause the VM execution in the remote session...");
5fced272b977bf1c44cfc74cb94b96346a0a34a5vboxsync getchar();
5fced272b977bf1c44cfc74cb94b96346a0a34a5vboxsync CHECK_RC (console->Pause());
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync printf ("Press enter to close this session...");
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync getchar();
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync session->Close();
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync }
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync while (FALSE);
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync printf ("\n");
a2e6357e0295f680b36aaf31bedd6409a5336165vboxsync#endif
3b9591b897f4b581f0be311535f93fd3a555c576vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync#if 0
7df95d48add893eab9003d793e18c099e126edf9vboxsync // open an existing remote session
7df95d48add893eab9003d793e18c099e126edf9vboxsync ///////////////////////////////////////////////////////////////////////////
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync do
7df95d48add893eab9003d793e18c099e126edf9vboxsync {
7df95d48add893eab9003d793e18c099e126edf9vboxsync ComPtr <IMachine> machine;
7df95d48add893eab9003d793e18c099e126edf9vboxsync Bstr name = "dos";
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync printf ("Getting a machine object named '%ls'...\n", name.raw());
7df95d48add893eab9003d793e18c099e126edf9vboxsync CHECK_RC_BREAK (virtualBox->FindMachine (name, machine.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync Guid guid;
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync CHECK_RC_BREAK (machine->COMGETTER(Id) (guid.asOutParam()));
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Opening an existing remote session for this machine...\n");
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync CHECK_RC_BREAK (virtualBox->OpenExistingSession (session, guid));
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync ComPtr <IMachine> sessionMachine;
1f72a47e266d9b7498b6a06aacf53a23ff874bc2vboxsync printf ("Getting sessioned machine object...\n");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_BREAK (session->COMGETTER(Machine) (sessionMachine.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync#if 0
ccc1001951ecd639b15b3034260c6012423349b3vboxsync Bstr extraDataKey = "VBoxSDL/SecureLabel";
ccc1001951ecd639b15b3034260c6012423349b3vboxsync Bstr extraData = "Das kommt jetzt noch viel krasser vom total konkreten API!";
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC (sessionMachine->SetExtraData (extraDataKey, extraData));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync#endif
ccc1001951ecd639b15b3034260c6012423349b3vboxsync#if 0
ccc1001951ecd639b15b3034260c6012423349b3vboxsync ComPtr <IConsole> console;
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Getting console object...\n");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to pause the VM execution in the remote session...");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync getchar();
ccc1001951ecd639b15b3034260c6012423349b3vboxsync CHECK_RC (console->Pause());
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to close this session...");
7df95d48add893eab9003d793e18c099e126edf9vboxsync getchar();
7df95d48add893eab9003d793e18c099e126edf9vboxsync#endif
7df95d48add893eab9003d793e18c099e126edf9vboxsync session->Close();
ccc1001951ecd639b15b3034260c6012423349b3vboxsync }
ccc1001951ecd639b15b3034260c6012423349b3vboxsync while (FALSE);
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("\n");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync#endif
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("Press enter to release Session and VirtualBox instances...");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync getchar();
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync // end "all-stuff" scope
ccc1001951ecd639b15b3034260c6012423349b3vboxsync ////////////////////////////////////////////////////////////////////////////
ccc1001951ecd639b15b3034260c6012423349b3vboxsync }
ccc1001951ecd639b15b3034260c6012423349b3vboxsync while (0);
d3144b8e0e6d348fc2d93462fcb0a3df2d373d36vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf("Press enter to shutdown COM...");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync getchar();
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync com::Shutdown();
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync printf ("tstAPI FINISHED.\n");
ccc1001951ecd639b15b3034260c6012423349b3vboxsync
ccc1001951ecd639b15b3034260c6012423349b3vboxsync return rc;
0deaf9b7b14fd7b44a999419acd224f002a2b13bvboxsync}
e554e8c589d84d4df49504e096f81dfa48c2a06evboxsync