Vss intialize for backup with return code E_UNEXPECTED
#include "vss.h"
#include "vswriter.h"
#include <VsBackup.h>
#include <stdio.h>
#define CHECK_PRINT(result) printf("%s\n",result==S_OK?"S_OK":"error")
int main(int argc, char* argv[])
{
BSTR xml;
LPTSTR errorText;
IVssBackupComponents *VssHandle;
HRESULT result = CreateVssBackupComponents(&VssHandle);
CHECK_PRINT(result);
result = VssHandle->InitializeForBackup();
printf("unexpected%x\n",result);
system("pause");
return 0;
}
in the above program, intializeforbackup fails with error code E_UNEXPECTED. The VSS service has started. In the event log this shows up as "Volume Shadow Copy Service error: Unexpected error calling procedure CoCreateInstance. Hr = 0x800401f0" ... Any solutions for InitializeForBackup to return S_OK?
a source to share
You need to initialize the COM library using the CoInitialize function.
HRESULT result = CoInitialize(NULL); CHECK_PRINT(result); result = CreateVssBackupComponents(&VssHandle); CHECK_PRINT(result); result = VssHandle->InitializeForBackup(); CHECK_PRINT(result);
This will give you all the S_OKs
a source to share