尝试运行卷影复制时"procedure entry not found in vssapi.dll"出现运行时错误



代码编译良好,我已将vssapi.lib包含在链接器的附加依赖项中。

我收到这个错误,说"在vssapi.dll中找不到CreatevssbackupcomponentsInternal过程入口点"

只有当我尝试在Windows服务器2003或Windows XP上运行它时,才会出现这个错误。它在Windows7上运行良好。

我将在下面附上代码,这是标准的影子复制代码。

// copy.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <winbase.h>
#include <vss.h>
#include <VsWriter.h>
#include <VsBackup.h>
int main()
{
    int retCode = 0;
    int i=0;
    HRESULT hr;
    IVssEnumObject *pIEnumSnapshots;
    IVssBackupComponents *ab;
    IVssAsync *pPrepareForBackupResults;
    GUID SnapshotSetID = GUID_NULL;
    VSS_OBJECT_PROP Prop;
    WCHAR wszVolumePathName[MAX_PATH]; 
    GUID snapshotID; 
    wcscpy(wszVolumePathName, L"E:\");
    VSS_SNAPSHOT_PROP snapshotProperties;
    WCHAR existingFilePath[MAX_PATH] = TEXT("\temp\");
    WCHAR newFileLocation[MAX_PATH] = TEXT("c:\Users\");
    LPWCH pwszExposed;
    int *x;
    LONG deletedsnapshots = 0 ;
    GUID nondeletedsnapshots;
    TCHAR existingFileLocation[MAX_PATH];
    if (CoInitialize(NULL) != S_OK)
    {
        printf("CoInitialize failed!n");
        return 1;
    }
    hr = CreateVssBackupComponents(&ab);
    if(hr != S_OK)
    {
        printf("Failed at CreateVssBackupComponents Stage");
        return 1;
    }
    hr = ab->InitializeForBackup();
    if(hr != S_OK)
    {
        printf("Failed at InitializeForBackup Stage");
        std::cout<<hr;
        return 1;
    }
    hr = ab->SetContext( VSS_CTX_FILE_SHARE_BACKUP);
    hr = ab->StartSnapshotSet(&SnapshotSetID);
    if(hr != S_OK)
    {
        printf("Failed at StartSnapshotset Stage");
        return 1;
    }
    hr = ab->AddToSnapshotSet(wszVolumePathName, GUID_NULL, &snapshotID); 
    if(hr != S_OK)
    {
        printf("Failed at AddtoSnapshotset Stage");
        return 1;
    }
    hr = ab->PrepareForBackup(&pPrepareForBackupResults);
    if(hr != S_OK)
    {
        printf("Failed at Backup");
    }
    hr = ab->DoSnapshotSet(&pPrepareForBackupResults);
    if(hr != S_OK)
    {
        printf("Failed at DoSnapshotset Stage");
        return 1;
    }
    while(true){
        pPrepareForBackupResults->QueryStatus(&hr, NULL);
        if(hr == VSS_S_ASYNC_FINISHED){
            break;
        }
    }
    hr = ab->GetSnapshotProperties(snapshotID, &snapshotProperties);
    if(hr != S_OK)
    {
        printf("Failed at GetSnapshotset Stage");
        return 1;
    }
    hr = ab->ExposeSnapshot(snapshotID, NULL, VSS_VOLSNAP_ATTR_EXPOSED_LOCALLY, L"C:ShadowOff", &pwszExposed);
    wcscpy(existingFilePath,snapshotProperties.m_pwszOriginalVolumeName);
    wcscat(existingFilePath, L"downloads\aa.exe");
    HANDLE hSourceFile = CreateFile(existingFilePath, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
    hr = ab->DeleteSnapshots(SnapshotSetID, VSS_OBJECT_SNAPSHOT_SET ,FALSE, &deletedsnapshots, &nondeletedsnapshots);
    if(hr != S_OK)
    {
        printf("Failed at DeleteSnapshotset Stage");
        return 1;
    }
    return retCode;
}

您必须使用Windows Vista之前的Windows版本的Windows卷影复制SDK:http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23490

相关内容

  • 没有找到相关文章

最新更新