It’s VirtualBox 6.0.6 Software Developer Kit (SDK) and VirtualBox 6.0.6 platform packages .
I have a problem. I want to recover a snapshot system, that was created early, but the program shows errors.
My code with comments:
Code: Select all
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;
}