Share via


Defining a Quota

The following example shows how to derive a quota from the quota template created in Using Templates to Define Quotas.

#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>
#include <stdio.h>
#include <comutil.h>
#include <FsrmQuota.h>  // quota objects
#include <FsrmTlb.h>    // Contains CLSIDs.


// Create a quota. Apply a template. Save the quota.

void wmain(void)
{
    HRESULT hr = S_OK;
    IFsrmQuotaManager* pqm = NULL;
    IFsrmQuota* pQuota = NULL;

    hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (FAILED(hr))
    {
        wprintf(L"CoInitializeEx() failed, 0x%x.\n", hr);
        return;
    }

    hr = CoCreateInstance(CLSID_FsrmQuotaManager, 
        NULL,
        CLSCTX_LOCAL_SERVER,
        __uuidof(IFsrmQuotaManager),
        reinterpret_cast<void**> (&amp;pqm));

    if (FAILED(hr))
    {
        wprintf(L"CoCreateInstance(FsrmQuotaManager) failed, 0x%x.\n", hr);
        goto cleanup;
    }

    hr = pqm->CreateQuota(_bstr_t(L"c:\\folder\\B"), &amp;pQuota);
    if (FAILED(hr))
    {
        wprintf(L"pqm->CreateQuota failed, 0x%x.\n", hr);
        goto cleanup;
    }

    hr = pQuota->ApplyTemplate(_bstr_t(L"Test Quota Template"));
    if (FAILED(hr))
    {
        wprintf(L"pQuota->ApplyTemplate failed, 0x%x.\n", hr);
        goto cleanup;
    }

    hr = pQuota->Commit();
    if (FAILED(hr))
    {
        wprintf(L"pQuota->Commit failed, 0x%x.\n", hr);
        goto cleanup;
    }

cleanup:

    if (pqm)
        pqm->Release();

    if (pQuota)
        pQuota->Release();

    CoUninitialize();
}