加载 VDS

[从 Windows 8 和 Windows Server 2012 开始,虚拟磁盘服务 COM 接口由 Windows 存储管理 API 取代。]

加载和初始化 VDS

  1. 释放非 null 接口。

  2. 调用 CoCreateInstanceCoCreateInstanceExCoGetClassObject 函数以获取指向服务加载程序对象的指针。

    无法 在此调用中指定CLSCTX_DISABLE_AAA。 如果调用 CoInitializeSecurity,则无法在 dwCapabilities 参数中指定EOAC_DISABLE_AAA

  3. 调用 IVdsServiceLoader::LoadService 方法以加载 VDS。

    NULL 作为第一个参数传递将加载并初始化本地主机上的 VDS。

  4. 调用 IVdsService::WaitForServiceReady 方法以等待 VDS 初始化完成。

下面的代码示例初始化返回指向服务对象的指针的服务。

#include "initguid.h"
#include "vds.h"
#include <stdio.h>

#pragma comment( lib, "ole32.lib" )

//
// Simple macro to release non-null interfaces.
//
#define _SafeRelease(x) {if (NULL != x) { x->Release(); x = NULL; } }

void __cdecl main(void) 
{
    HRESULT hResult;
    IVdsService *pService = NULL;
    IVdsServiceLoader *pLoader = NULL;

    // For this, you first get a pointer to the VDS Loader
    // Launch the VDS service. 
    //

    hResult = CoInitialize(NULL);

    if (SUCCEEDED(hResult)) 
    {
    
        hResult = CoCreateInstance(CLSID_VdsLoader,
            NULL,
            CLSCTX_LOCAL_SERVER,
            IID_IVdsServiceLoader,
            (void **) &pLoader);

        // 
        // And then load VDS on the local computer.
        //
        if (SUCCEEDED(hResult)) 
        {
            hResult = pLoader->LoadService(NULL, &pService);
        }

        //
        // You're done with the Loader interface at this point.
        //
        _SafeRelease(pLoader); 
        
        if (SUCCEEDED(hResult)) 
        {
            hResult = pService->WaitForServiceReady();
            if (SUCCEEDED(hResult)) 
            {
                //
                // You obtained an interface to the service: pService.
                // This interface can now be used to query for providers 
                // and perform other operations. 
                //
                printf("VDS Service Loaded");
            }

        } 
        else 
        {
            printf("VDS Service failed hr=%x\n",hResult);
        }
    }
}

使用 VDS

IVdsService::WaitForServiceReady

IVdsServiceLoader::LoadService

安装程序和服务对象