出现运行时错误“在 vssapi.dll 中找不到过程条目”尝试运行卷影复制时

发布于 2024-11-16 22:16:24 字数 3242 浏览 3 评论 0原文

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

我收到此错误消息“在 vssapi.dll 中找不到 CreatevssbackupcomponentsInternal 过程入口点”

并且仅当我尝试在 Windows Server 2003 或 Windows XP 上运行它时才会收到此错误。它在Windows 7上运行良好。

我将附上下面的代码,它是标准的卷影复制代码。

// 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;
}

The code compiles fine and I have included the vssapi.lib in the additional dependencies for the linker.

I get this error saying "CreatevssbackupcomponentsInternal procedure entry point could not be found in vssapi.dll"

And I get this error only when I try to run it on Windows server 2003 or Windows XP. It runs fine on Windows 7.

I will attach the code below, it is the standard shadow copy code.

// 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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2024-11-23 22:16:24

您必须使用适用于 Windows Vista 之前的 Windows 版本的 Windows Shadow Copy SDK:
http://www.microsoft.com/download/en /details.aspx?displaylang=en&id=23490

You have to use the Windows Shadow Copy SDK for Windows versions prior to Windows Vista:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23490

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文