打开注册表键 - RegistryOpenKey
函数简介
打开已存在的注册表键,用于后续读取或修改操作。
接口名称
RegistryOpenKey
DLL调用
int64_t RegistryOpenKey(int64_t instance, int32_t rootKey, const char* subKey);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| rootKey | 整数型 | 根键类型:0 HKEY_CLASSES_ROOT、1 HKEY_CURRENT_USER、2 HKEY_LOCAL_MACHINE、3 HKEY_USERS、4 HKEY_CURRENT_CONFIG |
| subKey | 字符串 | 子键路径,例如 "Software\Microsoft\Windows" |
示例
int64_t instance = CreateCOLAPlugInterFace();
int64_t key = RegistryOpenKey(instance, 1, "Software\\Microsoft\\Windows\\CurrentVersion");
if (key != 0) {
// 执行读写操作...
RegistryCloseKey(instance, key);
}
DestroyCOLAPlugInterFace(instance);
返回值
长整数型。成功返回注册表键句柄(非0值),失败返回 0。
注意事项
- 仅在键已存在时返回有效句柄,键不存在将返回 0。
- 使用完成后必须调用 RegistryCloseKey 释放句柄。
- 如果需要在键不存在时自动创建,请使用 RegistryCreateKey。
