Create VM using sdk-4.1.8

This is for discussing general topics about how to use VirtualBox.
Post Reply
vigneshrams
Posts: 13
Joined: 5. Jan 2012, 16:50
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: WINDOWS

Create VM using sdk-4.1.8

Post by vigneshrams »

Hi,
i am trying to create a VM using api in the sdk

Code: Select all

CoInitialize(NULL);

	IMachine *machine = NULL;
	IVirtualBox *virtualBox = NULL;
	BSTR guid = NULL;
	HRESULT hr;

	/* Instantiate the VirtualBox root object. */
	hr = CoCreateInstance(CLSID_VirtualBox, /* the VirtualBox base 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);
	BSTR strMachineName = ::SysAllocString(L"SampleMachine");
	IGuestOSType* os = NULL;
	BSTR type = ::SysAllocString(L"unknown");
	hr = virtualBox->GetGuestOSType(type, &os);
	os->get_Id(&guid);
	os->Release();
	BSTR null = ::SysAllocString(L"00000000-0000-0000-0000-000000000000");
	hr = virtualBox->CreateMachine(NULL, strMachineName, guid, null, TRUE, &machine);
	::SysFreeString(null);

	if (SUCCEEDED(hr))
	{
		IMedium* medium = NULL;
		ISession *session = NULL;
		IConsole *console = NULL;
		IProgress *progress = NULL;
		BSTR sessiontype = SysAllocString(L"gui");
		BSTR bstrPath = SysAllocString(L"I:\\VHD\\Local_disk_(C).vhd");
		hr = machine->SaveSettings();
		hr = virtualBox->RegisterMachine(machine);
		machine->Release();
		hr = virtualBox->FindMachine(strMachineName, &machine);
		hr = virtualBox->OpenMedium(bstrPath, DeviceType_HardDisk, AccessMode_ReadWrite,
			TRUE, &medium);
		/* Create the session object. */
		hr = CoCreateInstance(CLSID_Session, /* the VirtualBox base object */
			NULL, /* no aggregation */
			CLSCTX_INPROC_SERVER, /* the object lives in a server process on this machine */
			IID_ISession, /* IID of the interface */
			(void**)&session);
		hr = machine->LockMachine(session, LockType_Write);
		IStorageController* cont = NULL;
		BSTR loc = ::SysAllocString(L"BusLogic");
		hr = machine->AddStorageController(loc, StorageBus_SCSI, &cont);
		hr = machine->AttachDevice(loc, 0, 0, DeviceType_HardDisk, medium);
		/* Start a VM session using the delivered VBox GUI. */
		hr = machine->LaunchVMProcess(session, sessiontype,
			NULL, &progress);
		/* Wait until VM is running. */
		hr = progress->WaitForCompletion (-1);
		/* Get console object. */
		session->get_Console(&console);
		/* Bring console window to front. */
		machine->ShowConsoleWindow(0);
and my code fails at AddStorageController. What i am doing wrong here?

Thanks
Technologov
Volunteer
Posts: 3342
Joined: 10. May 2007, 16:59
Location: Israel

Re: Create VM using sdk-4.1.8

Post by Technologov »

I'd strongly recommend you to ask on vbox-dev mailing-list.

Also give some compiler errors, which can allow ppl to understand the problem.

Quick look at SDK docs shows that IMachine::addStorageController() accepts 2 parameters, not 3, but I'm not sure this is the issue.
vigneshrams
Posts: 13
Joined: 5. Jan 2012, 16:50
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: WINDOWS

Re: Create VM using sdk-4.1.8

Post by vigneshrams »

Hi,
The SDK Doc is not same as the version 4.1.8 . struck with it for a long time
Any help on this? please
vigneshrams
Posts: 13
Joined: 5. Jan 2012, 16:50
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: WINDOWS

Unable to attach the VMDK file in Virtualbox

Post by vigneshrams »

Hi,

I created a 2 VMDK files using VDDK 5.0. The first file was of used 500 MB and other one was higher size of 300 GB. When i try to attach these two files the 500 MB file attached but the higher size disk failed to attach with the below error message,
[Failed to open the hard disk D:\Viki\Disk0_full.vmdk.

Callee RC: VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)

]

please help on this.

/Thanks
Post Reply