Udostępnij przez


Ładowanie wirtualnych dysków wirtualnych

Począwszy od systemu Windows 8 i Windows Server 2012, interfejs Virtual Disk Service COM jest zastępowany przez API zarządzania pamięcią masową Windows.

Aby załadować i zainicjować usługę VDS

  1. Zwolnij interfejsy inne niż null.

  2. Wywołaj funkcję CoCreateInstance, CoCreateInstanceExlub coGetClassObject, aby uzyskać wskaźnik do obiektu modułu ładującego usługi.

    CLSCTX_DISABLE_AAA nie można określić w tym wywołaniu. Jeśli wywołano CoInitializeSecurity, nie można określić EOAC_DISABLE_AAA w parametrze dwCapabilities.

  3. Wywołaj metodę IVdsServiceLoader::LoadService, aby załadować VDS.

    Przekazywanie NULL jako pierwszy parametr ładuje i inicjuje usługi VDS na lokalnym hoście.

  4. Wywołaj metodę IVdsService::WaitForServiceReady, aby poczekać na ukończenie inicjowania usługi VDS.

Poniższy przykład kodu inicjuje usługę, która zwraca wskaźnik do obiektu usługi.

#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);
        }
    }
}

przy użyciu VDS

IVdsService::WaitForServiceReady

IVdsServiceLoader::LoadService

Setup i Obiekty Serwisowe