summaryrefslogtreecommitdiff
path: root/shared/ShadowCopy
diff options
context:
space:
mode:
Diffstat (limited to 'shared/ShadowCopy')
-rw-r--r--shared/ShadowCopy/shadow.cpp42
-rw-r--r--shared/ShadowCopy/shadow.h21
2 files changed, 30 insertions, 33 deletions
diff --git a/shared/ShadowCopy/shadow.cpp b/shared/ShadowCopy/shadow.cpp
index 2e739146..a5c280e8 100644
--- a/shared/ShadowCopy/shadow.cpp
+++ b/shared/ShadowCopy/shadow.cpp
@@ -5,11 +5,15 @@
// **************************************************************************
//
#include "shadow.h"
+#include <algorithm>
+#include <string>
+#include <comdef.h>
+#include "../com_ptr.h"
+#include "../com_error.h"
+#include "../c_dll.h"
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
-#include "../com_ptr.h"
-#include "../com_error.h"
#ifdef USE_SHADOW_XP
#include "xp/inc/vss.h"
@@ -24,41 +28,32 @@
adapt!
#endif
-#include <algorithm>
-#include <string>
-#include <cstdio>
-#include <comdef.h>
+using namespace c_dll;
-//typedef GUID VSS_ID;
-
-void writeString(const wchar_t* input, wchar_t* output, unsigned int outputBufferLen)
+namespace
{
- const size_t newSize = min(wcslen(input) + 1, outputBufferLen); //including null-termination
- memcpy(output, input, newSize * sizeof(wchar_t));
- output[newSize-1] = 0; //if output buffer is too small...
-}
-
+typedef HandleProvider<shadow::ShadowHandle, util::ComPtr<IVssBackupComponents> > HandleShadowMap;
void writeErrorMsg(const wchar_t* input, HRESULT hr, wchar_t* output, unsigned int outputBufferLen)
{
- writeString(Util::generateErrorMsg(input, hr).c_str(), output, outputBufferLen);
+ writeString(util::generateErrorMsg(input, hr).c_str(), output, outputBufferLen);
+}
}
-
bool shadow::createShadowCopy(const wchar_t* volumeName,
wchar_t* shadowVolName,
unsigned int shadowBufferLen,
- void** backupHandle,
+ ShadowHandle* handle,
wchar_t* errorMessage,
unsigned int errorBufferLen)
{
- using Util::ComPtr;
- using Util::generateErrorMsg;
+ using util::ComPtr;
+ using util::generateErrorMsg;
//MessageBox(0, L"backup err", L"", 0); */
- *backupHandle = NULL;
+ *handle = 0;
HRESULT hr = NULL;
ComPtr<IVssBackupComponents> backupComp;
@@ -171,14 +166,13 @@ bool shadow::createShadowCopy(const wchar_t* volumeName,
VssFreeSnapshotProperties(&props);
- *backupHandle = backupComp.release(); //release ownership
+ *handle = HandleShadowMap::instance().insert(backupComp);
return true;
}
-void shadow::releaseShadowCopy(void* backupHandle)
+void shadow::releaseShadowCopy(ShadowHandle handle)
{
- if (backupHandle != NULL)
- static_cast<IVssBackupComponents*>(backupHandle)->Release();
+ HandleShadowMap::instance().remove(handle);
}
diff --git a/shared/ShadowCopy/shadow.h b/shared/ShadowCopy/shadow.h
index a9120e8a..f1100284 100644
--- a/shared/ShadowCopy/shadow.h
+++ b/shared/ShadowCopy/shadow.h
@@ -18,32 +18,35 @@ namespace shadow
{
//COM needs to be initialized before calling any of these functions! CoInitializeEx/CoUninitialize
+typedef size_t ShadowHandle;
//volumeName must end with "\", while shadowVolName does not end with "\"
SHADOWDLL_API
-bool createShadowCopy(const wchar_t* volumeName,
- wchar_t* shadowVolName,
- unsigned int shadowBufferLen,
- void** backupHandle,
- wchar_t* errorMessage,
- unsigned int errorBufferLen);
+bool createShadowCopy(const wchar_t* volumeName, //[in]
+ wchar_t* shadowVolName, //[out]
+ unsigned int shadowBufferLen, //[in]
+ ShadowHandle* handle, //[out]
+ wchar_t* errorMessage, //[out]
+ unsigned int errorBufferLen); //[in]
//don't forget to release the backupHandle after shadow copy is not needed anymore!
SHADOWDLL_API
-void releaseShadowCopy(void* backupHandle);
+void releaseShadowCopy(ShadowHandle handle);
+//##########################################################################################
+
//function typedefs
typedef bool (*CreateShadowCopyFct)(const wchar_t* volumeName,
wchar_t* shadowVolName,
unsigned int shadowBufferLen,
- void** backupHandle,
+ ShadowHandle* handle,
wchar_t* errorMessage,
unsigned int errorBufferLen);
-typedef void (*ReleaseShadowCopyFct)(void* backupHandle);
+typedef void (*ReleaseShadowCopyFct)(ShadowHandle handle);
//function names
const char* const createShadowCopyFctName = "createShadowCopy";
bgstack15