1

VirtualBox SDK を使用して、プログラムで仮想マシンを作成しようとしています。これを行うために Windows 7 用の VirtualBox SDK の mscom サンプルを使用していますが、ハードディスクの作成に行き詰まっています。以下に示す CreateHardDisk メソッドはエラーを返します。提供されたドキュメントから、これを行う方法を理解できません。

bool createMachine(IVirtualBox *virtualBox)
{
HRESULT rc;
bool retVal = false;

IMachine *machine = NULL;
BSTR machineName = SysAllocString(L"TestVM");

rc = virtualBox->FindMachine(machineName, &machine);

if (FAILED(rc))
{
    //no machine found with this name so we create one
    BSTR osTypeName = SysAllocString(L"Ubuntu");
    rc = virtualBox->CreateMachine(NULL, machineName, NULL, osTypeName, NULL,  &machine );
    if(FAILED(rc))
    {
        printf("creation of test machine failed\n");
        return false;
    }
    printf("created TestVM virtual machine\n");

    //allocate 512 RAM
    rc = machine->put_MemorySize(512);
    if(FAILED(rc))
    {
        printf("put_MemorySize failed\n");
    }

    //create and allocate hdd
    IMedium* medium = NULL;
    BSTR format = SysAllocString(L"VDI");
    BSTR location = SysAllocString(L"test.vdi");

    //BSTR("VDI"), BSTR("TestHardDisk.vdi")
    rc = virtualBox->CreateHardDisk(format, location, &medium);
    if(FAILED(rc))//Here it returns false
    {
        //return false;
        printf("CreateHardDisk failed\n");
    }

    //save the settings for the virtual machine
    rc = machine->SaveSettings();
    if(FAILED(rc))
    {
        return false;
        printf("saveSettings failed\n");
    }

    //registers machine to the Pond server(Virtual Box)
    rc = virtualBox->RegisterMachine(machine);

    if(FAILED(rc))
    {
        return false;
        printf("register machine failed\n");
    }

    SAFE_RELEASE(progress);
    SysFreeString(osTypeName);
    SysFreeString(format);
    SysFreeString(location);
}

SysFreeString(machineName);
SAFE_RELEASE(machine);
return true;
}
4

0 に答える 0