|
#pragma once
#include <comutil.h>
template <class T>
class CProxy_ICpuLoadEvents : public IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>
{
//Warning this class will be regenerated by the wizard.
public:
HRESULT Measurement(LONG CpuLoad)
{
T* pT = static_cast<T*>(this);
int nConnectionIndex;
int nConnections;
int nValidConnections = 0;
CComVariant vars[1];
nConnections = m_vec.GetSize();
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
if (m_vec.GetAt(nConnectionIndex)) nValidConnections++;
}
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
HRESULT hr=S_OK;
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex); // Will AddRef() on client
pT->Unlock();
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch != NULL)
{
vars[0] = _variant_t(CpuLoad);
DISPPARAMS disp = { vars, NULL, 1, 0 };
CComVariant varResult;
EXCEPINFO stExcepInfo;
unsigned int uiArgErr = 0;
hr = pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, &stExcepInfo, &uiArgErr);
if (FAILED(hr))
{
return hr;
}
}
}
return S_OK;
}
#ifdef DEBUG
// This way we can see who subscribes
STDMETHODIMP Advise(IUnknown *pUnkSink, DWORD *pdwCookie)
{
HRESULT hr=S_OK;
hr = IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>::Advise(pUnkSink, pdwCookie);
return hr;
}
// This way we can see who un-subscribes
STDMETHODIMP Unadvise(DWORD dwCookie)
{
HRESULT hr=S_OK;
hr = IConnectionPointImpl<T, &__uuidof(_ICpuLoadEvents), CComDynamicUnkArray>::Unadvise(dwCookie);
return hr;
}
#endif
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.