📄 _icpuloadevents_cp.h
字号:
#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
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -