在Virtual Box中还原虚拟机快照时出错

时间:2019-04-26 13:08:25

标签: c# c++ com virtual-machine virtualbox

我将VirtualBox和Virtual Box API Microsoft Com C ++用于我的项目。 它是VirtualBox 6.0.6软件开发工具包(SDK)和VirtualBox 6.0.6平台软件包。
我有个问题。我想恢复早创建的快照系统,但是程序显示错误。
我的代码加上注释:

buffer = np.vstack([text1_vector.toarray(),
                text2_vector.toarray(),
                text3_vector.toarray(),
                text4_vector.toarray()])

similarity = cosine_similarity(text5_vector.toarray(), buffer)

此外,我创建了一个简单的C#应用​​程序,并在那里得到了完全相同的错误。怎么了?这是错误的API吗?我什至多次更改了操作系统(虚拟):

HRESULT rc; 

IVirtualBoxClient *virtualBoxClient = nullptr; 
IVirtualBox *virtualBox = nullptr; 
IMachine *machine = nullptr; 
ISession *session = nullptr; 
IProgress *progress = nullptr; 
ISnapshot* snapshot = nullptr; 

BSTR sessiontype = SysAllocString(L"gui"); 
BSTR machineName = SysAllocString(L"Win7x64"); 


HRESULT rc = CoCreateInstance(CLSID_VirtualBoxClient, NULL, CLSCTX_INPROC_SERVER, IID_IVirtualBoxClient, (void**)&virtualBoxClient); 

rc = virtualBoxClient->get_VirtualBox(&virtualBox); 

// looking for a machine with a name Win7x64 
rc = virtualBox->FindMachine(machineName, &machine); 

// create a session object 
rc = CoCreateInstance(CLSID_Session, NULL, CLSCTX_INPROC_SERVER, IID_ISession, (void**)&session); 
if (!SUCCEEDED(rc)) 
{ 
printf("Error creating Session instance! rc = 0x%x\n", rc); 
break; 
} 

// block the machine 
machine->LockMachine(session, LockType::LockType_Shared); 

// the name of the snapshot system 
BSTR snapshotUUID = SysAllocString(L"Win7_test_snapshot"); 
// looking for a snapshot system 
rc = machine->FindSnapshot(snapshotUUID, &snapshot); 
// recover snapshot. ERROR: variable rc - E_NOTIMPL Not implemented. 
rc = machine->RestoreSnapshot(snapshot, &progress); 

printf("Starting VM, please wait ...\n"); 
//waiting for the end of the operation. Abnormal termination- progress == nullptr ! 
rc = progress->WaitForCompletion(-1); 
// unlocking the machine 
rc = session->UnlockMachine(); 
if (!SUCCEEDED(rc)) 
{ 
printf("Error restore state machine!\n"); 
break; 
}

enter image description here

请问您如何解决调用方法错误“ RestoreSnapshot-E_NOTIMPL未实现”或如何正确还原系统快照?谢谢。

P.S .:我在官方论坛上提出了这个问题,但没有人帮助我。

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。快照应使用该会话的最新系统还原。因此代码如下:

HRESULT rc = machine->LockMachine(session, LockType::LockType_Shared);
rc = machine->FindSnapshot(snapshotUUID, &snapshot);
IMachine* currentMachine(nullptr);
rc = session->get_Machine(&currentMachine);
rc = currentMachine->RestoreSnapshot(snapshot, &progress);
rc = progress->WaitForCompletion(300000);
rc = session->UnlockMachine();

此代码适用。