HELP: MS Virtual Disk Service to Access Volumes and Discs on Local Machine.

Posted by Jibran Ahmed on Stack Overflow See other posts from Stack Overflow or by Jibran Ahmed
Published on 2010-05-14T04:32:16Z Indexed on 2010/05/14 4:34 UTC
Read the original article Hit count: 687

Filed under:

Hi, here it is my code through which I am successfully initialize the VDS service and get the Packs but When I call QueryVolumes on IVdsPack Object, I am able to get IEnumVdsObjects but unable to get IUnknown* array through IEnumVdsObject::Next method, it reutrns S_FALSE with IUnkown* = NULL. So this IUnknown* cant be used to QueryInterface for IVdsVolume

Below is my code

    HRESULT hResult;
IVdsService* pService = NULL;
IVdsServiceLoader *pLoader = NULL;

//Launch the VDS Service
hResult = CoInitialize(NULL);
if( SUCCEEDED(hResult) )
{
    hResult = CoCreateInstance( 
                                CLSID_VdsLoader,
                                NULL,
                                CLSCTX_LOCAL_SERVER,
                                IID_IVdsServiceLoader,
                                (void**) &pLoader
                                );

    //if succeeded load VDS on local machine
    if( SUCCEEDED(hResult) )
        pLoader->LoadService(NULL, &pService);

    //Done with Loader now release VDS Loader interface
    _SafeRelease(pLoader);

    if( SUCCEEDED(hResult) )
    {
        hResult = pService->WaitForServiceReady();
        if ( SUCCEEDED(hResult) )
        {
            AfxMessageBox(L"VDS Service Loaded");
            IEnumVdsObject* pEnumVdsObject = NULL;
            hResult = pService->QueryProviders(VDS_QUERY_SOFTWARE_PROVIDERS, &pEnumVdsObject);

            IUnknown* ppObjUnk ;
            IVdsSwProvider* pVdsSwProvider = NULL;
            IVdsPack* pVdsPack = NULL;
            IVdsVolume* pVdsVolume = NULL;
            ULONG ulFetched = 0;

            hResult = E_INVALIDARG;
            while(!SUCCEEDED(hResult))
            {
                hResult = pEnumVdsObject->Next(1, &ppObjUnk, &ulFetched);
                hResult = ppObjUnk->QueryInterface(IID_IVdsSwProvider, (void**)&pVdsSwProvider);
                if(!SUCCEEDED(hResult))
                    _SafeRelease(ppObjUnk);
            }
            _SafeRelease(pEnumVdsObject);
            _SafeRelease(ppObjUnk);

            hResult = pVdsSwProvider->QueryPacks(&pEnumVdsObject);

            hResult = E_INVALIDARG;
            while(!SUCCEEDED(hResult))
            {
                hResult = pEnumVdsObject->Next(1, &ppObjUnk, &ulFetched);
                hResult = ppObjUnk->QueryInterface(IID_IVdsPack, (void**)&pVdsPack);
                if(!SUCCEEDED(hResult))
                    _SafeRelease(ppObjUnk);
            }

            _SafeRelease(pEnumVdsObject);
            _SafeRelease(ppObjUnk);

            hResult = pVdsPack->QueryVolumes(&pEnumVdsObject);
            pEnumVdsObject->Reset();

            hResult = E_INVALIDARG;
            ulFetched = 0;
            BOOL bDone = FALSE;
            while(!SUCCEEDED(hResult))
            {
                hResult = pEnumVdsObject->Next(1, &ppObjUnk, &ulFetched);
                //hResult = ppObjUnk->QueryInterface(IID_IVdsVolume, (void**)&pVdsVolume);
                if(!SUCCEEDED(hResult))
                    _SafeRelease(ppObjUnk);
            }
            _SafeRelease(pEnumVdsObject);
            _SafeRelease(ppObjUnk);
            _SafeRelease(pVdsPack);
            _SafeRelease(pVdsSwProvider);

// hResult = pVdsVolume->AddAccessPath(TEXT("G:\"));

            if(SUCCEEDED(hResult))
                AfxMessageBox(L"Add Access Path Successfully");
            else
                AfxMessageBox(L"Unable to Add access path");

            //UUID of IVdsVolumeMF {EE2D5DED-6236-4169-931D-B9778CE03DC6}
            static const GUID GUID_IVdsVolumeMF = {0xEE2D5DED, 0x6236, 4169,{0x93, 0x1D, 0xB9, 0x77, 0x8C, 0xE0, 0x3D, 0XC6} };

            hResult = pService->GetObject(GUID_IVdsVolumeMF, VDS_OT_VOLUME, &ppObjUnk);
            if(hResult == VDS_E_OBJECT_NOT_FOUND)
                AfxMessageBox(L"Object Not found");
            if(hResult == VDS_E_INITIALIZED_FAILED)
                AfxMessageBox(L"Initialization failed");

// pVdsVolume = reinterpret_cast(ppObjUnk);

            if(SUCCEEDED(hResult))
            {

// hResult = pVdsVolume->AddAccessPath(TEXT("G:\")); if(SUCCEEDED(hResult)) { IVdsAsync* ppVdsSync; AfxMessageBox(L"Formatting is about to Start......"); // hResult = pVdsVolume->Format(VDS_FST_UDF, TEXT("UDF_FORMAT_TEST"), 2048, TRUE, FALSE, FALSE, &ppVdsSync); if(SUCCEEDED(hResult)) AfxMessageBox(L"Formatting Started......."); else AfxMessageBox(L"Formatting Failed"); } else AfxMessageBox(L"Unable to Add Access Path"); } _SafeRelease(pVdsVolume); }

        else
        {
            AfxMessageBox(L"VDS Service Cannot be Loaded");
        }
    }
}
_SafeRelease(pService);

© Stack Overflow or respective owner

Related posts about visual-c++