作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
class Win32_PerfRawData_Tcpip_NetworkInterface : Win32_PerfRawData
{
uint32 BytesReceivedPerSec;
uint32 BytesSentPerSec;
uint64 BytesTotalPerSec;
string Caption;
uint32 CurrentBandwidth;
string Description;
uint64 Frequency_Object;
uint64 Frequency_PerfTime;
uint64 Frequency_Sys100NS;
string Name;
uint32 OutputQueueLength;
uint32 PacketsOutboundDiscarded;
uint32 PacketsOutboundErrors;
uint32 PacketsPerSec;
uint32 PacketsReceivedDiscarded;
uint32 PacketsReceivedErrors;
uint32 PacketsReceivedNonUnicastPerSec;
uint32 PacketsReceivedPerSec;
uint32 PacketsReceivedUnicastPerSec;
uint32 PacketsReceivedUnknown;
uint32 PacketsSentNonUnicastPerSec;
uint32 PacketsSentPerSec;
uint32 PacketsSentUnicastPerSec;
uint64 Timestamp_Object;
uint64 Timestamp_PerfTime;
uint64 Timestamp_Sys100NS;
};
这个 WMI 类。
我得到 PacketReceived/sec 但它的值高于 120000。我认为它每秒接收的字节数。我得到了其他值及其正确
int WMIClass::ExcuteQuery(const char* cstr,LPWSTR atrb)
{
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t(cstr),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
while (pEnumerator)
{
hres = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
// Get the value of the Name property
hres = pclsObj->Get(atrb, 0, &vtProp, 0, 0);
intVal=vtProp.uintVal;
}
return intVal;
}
程序正常执行并且可以轻松读取值,但我对这个值有疑问。我需要在网络适配器上每秒收到的数据包。任何简单的解决方案?如果在 Qt 框架中,将不胜感激。
最佳答案
确保正确初始化 intVal:
int WMIClass::ExcuteQuery(const char* cstr,LPWSTR atrb) {
int intVal = 0;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t(cstr),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
while (pEnumerator) {
hres = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
break;
VARIANT vtProp;
// Get the value of the Name property
hres = pclsObj->Get(atrb, 0, &vtProp, 0, 0);
intVal = vtProp.uintVal;
}
return intVal;
}
关于c++ - PacketReceived/Sec 值非常高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20225921/
class Win32_PerfRawData_Tcpip_NetworkInterface : Win32_PerfRawData { uint32 BytesReceivedPerSec;
我是一名优秀的程序员,十分优秀!