Share via


載入 VD

[從Windows 8和Windows Server 2012開始,虛擬磁碟服務COM 介面會由Windows 儲存體管理 API取代。

載入和初始化 VDS

  1. 釋放非 Null 介面。

  2. 呼叫CoCreateInstance、CoCreateInstanceExCoGetClassObject函式,以取得服務載入器物件的指標。

    無法 在此呼叫中指定CLSCTX_DISABLE_AAA。 如果呼叫CoInitializeSecurity,就無法在dwCapabilities參數中指定EOAC_DISABLE_AAA

  3. 呼叫 IVdsServiceLoader::LoadService 方法來載入 VDS。

    當第一個參數載入並初始化本機主機上的 VDS 時傳遞 Null

  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

安裝程式和服務物件