Chargement de VDS
[à partir de Windows 8 et Windows Server 2012, l’interface COM du Service de disque virtuel est remplacée par l' API de gestion des Stockage Windows.]
Pour charger et initialiser VDS
Libère les interfaces non null.
Appelez la fonction CoCreateInstance, CoCreateInstanceExou CoGetClassObject pour obtenir un pointeur vers l’objet service Loader.
CLSCTX _ Impossible _ de spécifier AAA dans cet appel. Si la méthode CoInitializeSecurity est appelée, EOAC _ Disable _ AAA ne peut pas être spécifié dans le paramètre dwCapabilities .
Appelez la méthode IVdsServiceLoader :: LoadService pour charger VDS.
Le passage de la valeur null en tant que premier paramètre charge et initialise VDS sur l’hôte local.
Appelez la méthode IVdsService :: WaitForServiceReady pour attendre la fin de l’initialisation de VDS.
L’exemple de code suivant initialise le service qui retourne un pointeur vers l’objet de service.
#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);
}
}
}