VSS Intializefor备份失败,返回代码E_UNEDECT
-
03-10-2019 - |
题
#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_UNEDECT失败。 VSS服务正在运行。在事件日志中,它显示为“音量阴影复制服务错误:意外错误调用例程cocreateinstance。HR= 0x800401f0。
解决方案
您需要使用COINITIALIZE函数初始化COM库。
HRESULT result = CoInitialize(NULL);
CHECK_PRINT(result);
result = CreateVssBackupComponents(&VssHandle);
CHECK_PRINT(result);
result = VssHandle->InitializeForBackup();
CHECK_PRINT(result);
这将为您提供所有S_OKS
不隶属于 StackOverflow