读取64位整型值 - RegistryGetQword
函数简介
读取64位整型的注册表值(REG_QWORD),用于获取大数值型配置。
接口名称
RegistryGetQword
DLL调用
int64_t RegistryGetQword(int64_t instance, int64_t key, const char* valueName)
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。key(长整型数): 注册表键句柄,由 RegistryOpenKey 或 RegistryCreateKey 返回valueName(字符串): 值名称
示例:
// 创建OLA对象
int64_t instance = CreateCOLAPlugInterFace();
// 打开注册表键
int64_t key = RegistryOpenKey(instance, 1, "Software\\OLAPlug\\Statistics");
if (key != 0) {
// 读取总访问次数
int64_t totalVisits = RegistryGetQword(instance, key, "TotalVisits");
printf("总访问次数: %lld\n", totalVisits);
// 读取文件大小
int64_t fileSize = RegistryGetQword(instance, key, "FileSize");
printf("文件大小: %lld 字节 (%.2f GB)\n", fileSize, fileSize / (1024.0 * 1024.0 * 1024.0));
// 读取时间戳
int64_t timestamp = RegistryGetQword(instance, key, "LastUpdate");
printf("最后更新时间戳: %lld\n", timestamp);
// 关闭注册表键
RegistryCloseKey(instance, key);
}
// 释放资源
DestroyCOLAPlugInterFace(instance);
返回值
长整型数:
- 成功: 返回读取到的64位整型值
- 失败或不存在: 返回 0
注意事项
- 如果值不存在或类型不匹配,将返回 0
- 无法区分返回的 0 是实际值还是错误标志
- REG_QWORD 类型为64位无符号整数
- 适用于读取大数值,如文件大小、时间戳等
- 读取前建议确认值的类型正确
