vss intializefor backup fails with return code E_UNEXPECTED

2
#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 is running . In the event log it shows as "Volume Shadow Copy Service error: Unexpected error calling routine CoCreateInstance. hr = 0x800401f0.".. Any solutions for the InitializeForBackup to return S_OK?

c++
windows
volume-shadow-service
asked on Stack Overflow May 4, 2010 by suresh • edited May 23, 2010 by Jon Seigel

1 Answer

2

You need to initialize the COM library with 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 S_OKs

answered on Stack Overflow Aug 27, 2010 by lalli

User contributions licensed under CC BY-SA 3.0