vss intializefor backup失败,返回码为E_UNEXPECTED

时间:2010-05-04 22:14:35

标签: c++ windows volume-shadow-service

#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;
}
上述程序intializeforbackup中的

失败,错误代码为E_UNEXPECTED。 VSS服务正在运行。在事件日志中,它显示为“卷影复制服务错误:意外错误调用例程CoCreateInstance.hr = 0x800401f0。”..任何InitializeForBackup返回S_OK的解决方案?

1 个答案:

答案 0 :(得分:2)

您需要使用CoInitialize函数初始化COM库。

HRESULT  result = CoInitialize(NULL);
CHECK_PRINT(result);
result = CreateVssBackupComponents(&VssHandle);
CHECK_PRINT(result);
result = VssHandle->InitializeForBackup();
CHECK_PRINT(result);

这将为您提供所有S_OKs