Using Virtual Box COM APIs to list the Virtual machine snapshots


	int Helper_ReturnVms(IVirtualBox *virtualBox)
	{
		HRESULT rc;
		bool bFound=false;
		/*
		* First we have to get a list of all registered VMs
		*/
		SAFEARRAY *machinesArray = NULL;
		rc = virtualBox->get_Machines(&machinesArray);
		if(FAILED(rc))
		{
			SafeArrayDestroy (machinesArray);
			return -1;
		}
		IMachine **machines;
		rc = SafeArrayAccessData (machinesArray, (void **) &machines);
		if(FAILED(rc))
		{
			SafeArrayUnaccessData (machinesArray);
			SafeArrayDestroy (machinesArray);
			return -1;
		}
		for (ULONG i = 0; i rgsabound[0].cElements; ++i)
		{
			BSTR str;
			//rc = machines[i]->get_Name(&str);
			rc = machines[i]->get_Id(&str);
			if(FAILED(rc))
			{
				SysFreeString(str);
				SafeArrayUnaccessData (machinesArray);
				SafeArrayDestroy (machinesArray);
			}
			printf("Name: %Sn", str);
			SysFreeString(str);
		}
		SafeArrayUnaccessData (machinesArray);
		SafeArrayDestroy (machinesArray);
		return 0;
	}

Leave a Reply

Your email address will not be published. Required fields are marked *