c++ - native WMI 提供程序中的 UINT64 不会在某些系统上返回数据

标签 c++ com wmi

我在 This tutorial on MSDN 之后创建了一个本地 WMI 提供程序.我的类(class) MOF 看起来与此类似:

[dynamic, provider("CacheProvider")]
class Cache
{
    [key]
    String Path;
    uint32 Type;
    uint64 MaxSize;
    uint64 Size;
    boolean Enabled;
};

除 uint64 值外,所有数据均正确返回。我读过,对于 uint64 值,您实际上需要将数据作为 BSTR 提供。它确实适用于我试过的 99% 的机器。这就是我实现这一目标的方式。

v.vt = VT_BSTR;
v.bstrVal = ToLongLongString(MaxSize);
sc = (*pNewInst)->Put(L"MaxSize", 0, &v, 0);
VariantClear(&v);

ToLongLongString 函数如下所示。

bstr_t ToLongLongString(LONGLONG llValue)
{
    wchar_t szValue[21];
    SecureZeroMemory(szValue, sizeof(szValue));
    swprintf_s(szValue, L"%lld", llValue);
    bstr_t bstrFormat(szValue);
    return bstrFormat;
}

我已验证此函数返回的字符串格式正确。看起来无论出于何种原因,它都没有通过 WMI 系统。我唯一没有看到它工作的机器是 2012 R2 服务器。

最佳答案

从这里开始: http://msdn.microsoft.com/en-us/library/aa393262(v=vs.85).aspx

Note When querying for property values with a uint64 or sint64 data type in a scripting language like VBScript, WMI returns string values. Unexpected results can occur when comparing these values, because comparing strings returns different results than comparing numbers. For example, "10000000000" is less than "9" when comparing strings, and 9 is less than 10000000000 when comparing numbers. To avoid confusion you should use the CDbl method in VBScript when properties of type uint64 or sint64 are retrieved from WMI.

你可以尝试使用 CDBL 吗?

关于c++ - native WMI 提供程序中的 UINT64 不会在某些系统上返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20427449/

相关文章:

powershell - Powershell中,如何检索现有策略设置(Win8.1/server 2012 r2 core)

c++ - 为什么 crtp 适用于结构而不适用于类?

c++ - 默认(可选)参数作为引用 c++

c++ - 如何在 Linux 中从动态库(libsample.so)生成导入库(libsample.a)

excel - 使用 matlab 添加迷你图到 Excel

c# - 允许连接到完整性级别不匹配的 .NET COM 服务器

asp.net - 使用 IIS 下运行的 ASP.NET 控制 iTunes

powershell - 如何通过 WMI 读取应用程序和服务日志?

c - 使用 IOCTL_STORAGE_QUERY_PROPERTY 获取序列号

C++队列非锁定