Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Ta klasa pomocnika ma zależność o niskiej kondycji od klasy SimpleFileHelperClass zakodowanej w pierwszym przykładzie.
Druga klasa pomocnika przekazywania jest prostą klasą pomocnika przekazującego, która nie wykonuje żadnej diagnozy. Zamiast tego zawsze generuje hipotezę o niższym zdrowiu dla Klasy SimpleFileHelperClass. Jest to przydatne w obsłudze jako symbol zastępczy na potrzeby przyszłego dodawania możliwości diagnostyki w tej klasie pomocniczej. Klasa pomocnika przekazywania implementuje dwie metody.
Metoda LowHealth służy do ustawiania stanu diagnozy na DS_INDETERMINATE. Dzięki temu funkcja NDF wywołuje metodę 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;
}
Następnie zaimplementowano metodę GetLowerHypotheses, aby poinformować NDF, która klasa pomocnika ma zdiagnozować.
#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;
}