[從 Windows 8 和 Windows Server 2012 開始,虛擬磁碟服務 COM 介面會由 Windows 記憶體管理 API取代。
載入和初始化 VDS
釋放非空接口。
呼叫 CoCreateInstance、CoCreateInstanceEx或 CoGetClassObject 函式,以取得服務載入器物件的指標。
無法在此呼叫中指定 CLSCTX_DISABLE_AAA。 如果呼叫 CoInitializeSecurity,則無法在 dwCapabilities 參數中指定 EOAC_DISABLE_AAA。
呼叫 IVdsServiceLoader::LoadService 方法來載入 VDS。
將 NULL 作為第一個參數傳遞時,會在本機主機上載入並初始化 VDS。
呼叫 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);
}
}
}
相關主題