Extension de classe d’assistance NDF avec remise
Cette classe d’assistance a une dépendance d’intégrité faible sur le SimpleFileHelperClass codé dans le premier exemple.
La deuxième classe d’assistance de transfert est une classe d’assistance directe simple qui n’effectue pas de diagnostic lui-même. Au lieu de cela, il génère toujours une hypothèse d’intégrité inférieure pour le SimpleFileHelperClass. Cela est utile pour servir d’espace réservé pour l’ajout ultérieur de la fonctionnalité de diagnostic dans cette classe d’assistance. La classe d’assistance de transfert implémente deux méthodes.
La méthode LowHealth est utilisée pour définir l’état du diagnostic sur DS _ Indeterminate. Cela rend l’appel NDF GetLowerHypotheses.
#include <windows.h>
HRESULT HandOffTestHelperClass::LowHealth(
/* [unique][string][in] */ LPCWSTR pwszInstanceDescription,
/* [string][out] */ LPWSTR *ppwszDescription,
/* [out] */ long *pDeferredTime,
/* [out] */ DIAGNOSIS_STATUS *pStatus)
{
*pStatus = DS_INDETERMINATE;
return S_OK;
}
Ensuite, GetLowerHypotheses est implémenté pour indiquer à NDF la classe d’assistance à diagnostiquer.
#include <windows.h>
HRESULT HandOffTestHelperClass::GetLowerHypotheses(
ULONG *Count,
HYPOTHESIS **Hypotheses)
{
HRESULT hr = S_OK;
HYPOTHESIS *pHypothesis=NULL;
HELPER_ATTRIBUTE *pAttr=NULL;
pHypothesis = (PHYPOTHESIS)CoTaskMemAlloc(sizeof(HYPOTHESIS));
if (pHypothesis == NULL)
{
return E_OUTOFMEMORY;
}
SecureZeroMemory(pHypothesis, sizeof(HYPOTHESIS));
pAttr = (PHELPER_ATTRIBUTE)CoTaskMemAlloc(sizeof(HELPER_ATTRIBUTE));
if (pAttr == NULL)
{
hr = E_OUTOFMEMORY;
goto Error;
}
SecureZeroMemory(pAttr, sizeof(HELPER_ATTRIBUTE));
//set the helper class name to hand off to
hr = StringCchCopyWithAlloc(&pHypothesis->pwszClassName, MAX_PATH,
L"SimpleFileHelperClass");
if (FAILED(hr))
{
goto Error;
}
//populate the attribute
//set the attribute name
hr = StringCchCopyWithAlloc(&pAttr->pwszName, MAX_PATH, L"filename");
if (FAILED(hr))
{
goto Error;
}
//set attribute data
pAttr->type = AT_STRING;
hr = StringCchCopyWithAlloc(&pAttr->PWStr, MAX_PATH, m_pwszTestFile);
if (FAILED(hr))
{
goto Error;
}
//set the attributes to the hypothesis
pHypothesis->celt = 1; //number of attributes
pHypothesis->rgAttributes=pAttr;
//pass data back
*pcelt = 1; //one hypothesis
*pprgHypotheses = pHypothesis;
return S_OK;
Error:
if (pAttr)
{
if (pAttr->PWStr)
CoTaskMemFree(pAttr->PWStr);
if (pAttr->pwszName)
CoTaskMemFree(pAttr->pwszName);
}
if (pHypothesis)
{
if (pHypothesis->pwszClassName)
CoTaskMemFree(pHypothesis->pwszClassName);
CoTaskMemFree(pHypothesis);
}
return hr;
}