Loading VDS
[Beginning with Windows 8 and Windows Server 2012, the Virtual Disk Service COM interface is superseded by the Windows Storage Management API.]
To load and initialize VDS
Release non-null interfaces.
Call the CoCreateInstance, CoCreateInstanceEx, or CoGetClassObject function to obtain a pointer to the service loader object.
CLSCTX_DISABLE_AAA cannot be specified in this call. If CoInitializeSecurity is called, EOAC_DISABLE_AAA cannot be specified in the dwCapabilities parameter.
Call the IVdsServiceLoader::LoadService method to load VDS.
Passing NULL as the first parameter loads and initializes VDS on the local host.
Call the IVdsService::WaitForServiceReady method to wait for VDS initialization to complete.
The following code example initializes the service that returns a pointer to the service object.
#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);
}
}
}
Related topics