test classes
Globals
About(HWND, UINT, WPARAM)
InitInstance(HINSTANCE, int nClass)
MyRegisterClass(HINSTANCE)
WimMain(HINSTANCE)
WinProc(HWND, UINT, WPARAM)
hlnst
szTitle
szWindowClass
#include "stdafx.h"
// constructor
VssClient::VssClient()
{
m_bCoInitializeCalled = false;
m_dwContext = VSS_CTX_BACKUP;
m_latestSnapshotSetID = GUID_NULL;
m_bDuringRestore = false;
}
// destructor
VssClient::~VssClient()
{
// release the IVssBackupComponents interface
// WARNING: this must be done BEFORE calling CoUninitialize()
m_pVssObject = NULL;
// call CoUninitialize if the CoInitialize was performed sucesfully
if (m_bCoInitializeCalled)
CoUninitialize();
}
// initialize the COM infrastructure and the internal pointers
void VssClient::Initialize(DWORD dwContext, wstring xmlDoc, bool bDuringRestore)
{
FunctionTracer ft(DBG_INFO);
// initialize COM
CHECK_COM( CoInitialize(NULL) );
m_bCoInitializeCalled = true;
// initialize COM security
CHECK_COM(
CoInitializeSecurity(
NULL, // allow all VSS writers to communicate back
-1, // default COM authentication service
NULL, // default COM authorization service
NULL, // reserved param
RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // strongest COM authentication level
RPC_C_IMP_LEVEL_IMPERSONATE, // minimal impersonation abilities
NULL, // default COM authentication settings
EOAC_DYNAMIC_CLOAKING, // cloaking
NULL // reserved param
) );
// create the internal backup components object
CHECK_COM( CreateVssBackupComponents(&m_pVssObject) );
// we doing a restore now?
m_bDuringRestore = bDuringRestore;
// call either Initialize for backup or for restore
if (m_bDuringRestore)
{
CHECK_COM(m_pVssObject->InitializeForRestore(CComBSTR(xmlDoc.c_str())))
}
else
{
// initialize for backup
if (xmlDoc.length() == 0)
CHECK_COM(m_pVssObject->InitializeForBackup())
else
CHECK_COM(m_pVssObject->InitializeForBackup(CComBSTR(xmlDoc.c_str())))
#ifdef VSS_SERVER
// set the context, if different than the default context
if (dwContext != VSS_CTX_BACKUP)
{
ft.WriteLine(L"- setting the VSS context to: 0x%08lx", dwContext);
CHECK_COM(m_pVssObject->SetContext(dwContext) );
}
#endif
}
// keep the context
m_dwContext = dwContext;
// set various properties per backup components instance
CHECK_COM(m_pVssObject->SetBackupState(true, true, VSS_BT_FULL, false));
}
// waits for the completion of the asynchronous operation
void VssClient::WaitAndCheckForAsyncOperation(IVssAsync* pAsync)
{
FunctionTracer ft(DBG_INFO);
ft.WriteLine(L"(waiting for the asynchronous operation to finish...)");
// wait until the async operation finishes
CHECK_COM(pAsync->Wait());
// check the result of the asynchronous operation
HRESULT hrReturned = S_OK;
CHECK_COM(pAsync->QueryStatus(&hrReturned, NULL));
// check if the async operation succeeded...
if(FAILED(hrReturned))
{
ft.WriteLine(L"error during the last asynchronous operation.");
ft.WriteLine(L"- returned HRESULT = 0x%08lx", hrReturned);
ft.WriteLine(L"- error text: %s", FunctionTracer::HResult2String(hrReturned).c_str());
ft.WriteLine(L"- please re-run VSHADOW.EXE with the /tracing option to get more details");
throw(hrReturned);
}
}