void CProfileSettings::SetModified()
{
	// Quit if already dirty
	if (m_bModified)
		return;

	m_bModified=true;

	if (m_hCallbackTimer==NULL)
	{
		m_hCallbackTimer=SetCallbackTimer(10, 0, ProfileSettingsFlushProc, (LPARAM)this);
	}
}
HRESULT CVBoxMachine::Open()
{
	// Check not already open
	ASSERT(!IsOpen());

	// Create VirtualBox object
	log("Creating VirtualBox\n");
	ClearComErrorInfo();
	HRESULT hr=m_spVirtualBox.CoCreateInstance(__uuidof(VirtualBox));
	if (FAILED(hr))
	{
		Close();
		return SetError(Format(L"Failed to create VirtualBox COM server - %s", vboxFormatError(hr)));
	}

	// Get machine ID
	log("Finding machine\n");
	ClearComErrorInfo();
	hr=m_spVirtualBox->FindMachine(CComBSTR(m_strMachineName), &m_spMachine);
	if (FAILED(hr) || m_spMachine==NULL)
	{
		Close();
		return SetError(Format(L"Machine \"%s\" not found - %s", m_strMachineName, vboxFormatError(hr)));
	}
	m_spMachine->get_Id(&m_bstrMachineID);

	// Open log file
	CComBSTR bstrLogFolder;
	m_spMachine->get_LogFolder(&bstrLogFolder);
	log_open(w2a(SimplePathAppend(bstrLogFolder, L"VBoxHeadlessTray.log")));

	// Connect listener for IVirtualBoxCallback
	log("Registering virtualbox callback\n");
	CComPtr<IEventSource> spEventSource;
	m_spVirtualBox->get_EventSource(&spEventSource);


	SAFEARRAYBOUND bound;
	bound.lLbound=0;
	bound.cElements=1;
	SAFEARRAY* interesting = SafeArrayCreate(VT_I4, 1, &bound);
	int* pinteresting;
	SafeArrayAccessData(interesting, (void**)&pinteresting);
	pinteresting[0]=VBoxEventType_OnMachineStateChanged;
	SafeArrayUnaccessData(interesting);
	spEventSource->RegisterListener(&m_EventListener, interesting, VARIANT_TRUE);
	SafeArrayDestroy(interesting);

	// Since VBox 4.1 seems to fail to send machine state events, lets just poll the machine every 5 seconds
	// If we get a real machine state event, we'll kill this, assuming it's working
	// The VBoxHeadlessTray machine window also calls OnMachineStateChanged from it's tray icon
	// update timer.... so when things are transitioning the state should update fairly quickly.
	m_hPollTimer = SetCallbackTimer(1000, 0, OnPollMachineState, (LPARAM)this);

	m_bCallbackRegistered=true;

	m_spMachine->get_State(&m_State);


	return S_OK;
}