创建注册表键 - RegistryCreateKey
函数简介
创建并打开注册表键,如果键已存在则直接打开。
接口名称
RegistryCreateKey
DLL调用
int64_t RegistryCreateKey(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\OLAPlug" |
示例
int64_t instance = CreateCOLAPlugInterFace();
int64_t key = RegistryCreateKey(instance, 1, "Software\\OLAPlug\\Config");
if (key != 0) {
RegistrySetString(instance, key, "AppName", "OLAPlug");
RegistrySetDword(instance, key, "Version", 100);
RegistryCloseKey(instance, key);
}
DestroyCOLAPlugInterFace(instance);
返回值
长整数型。成功返回注册表键句柄(非0值),失败返回 0。
注意事项
- 如果键已存在,则直接打开已有键,不会覆盖现有数据。
- 使用完成后必须调用 RegistryCloseKey 释放句柄。
- 创建 HKEY_LOCAL_MACHINE 下的键可能需要管理员权限。
- 如果仅需打开已存在的键,建议使用 RegistryOpenKey。
