设置字符串值 - RegistrySetString
函数简介
设置字符串类型的注册表值(REG_SZ),用于存储文本信息。
接口名称
RegistrySetString
DLL调用
int32_t RegistrySetString(int64_t instance, int64_t key, const char* valueName, const char* value)
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。key(长整型数): 注册表键句柄,由 RegistryOpenKey 或 RegistryCreateKey 返回valueName(字符串): 值名称,空字符串表示默认值value(字符串): 字符串值内容
示例:
// 创建OLA对象
int64_t instance = CreateCOLAPlugInterFace();
// 创建或打开注册表键
int64_t key = RegistryCreateKey(instance, 1, "Software\\OLAPlug\\Config");
if (key != 0) {
// 设置字符串值
int32_t result = RegistrySetString(instance, key, "AppName", "OLAPlug Application");
if (result == 1) {
printf("成功设置字符串值\n");
}
// 设置默认值
result = RegistrySetString(instance, key, "", "默认配置");
// 设置路径值
result = RegistrySetString(instance, key, "InstallPath", "C:\\Program Files\\OLAPlug");
// 关闭注册表键
RegistryCloseKey(instance, key);
}
// 释放资源
DestroyCOLAPlugInterFace(instance);
返回值
整型数:
- 1: 成功
- 0: 失败
注意事项
- 如果值名称已存在,将覆盖原有值
- 空字符串作为值名称表示设置默认值
- 字符串值类型为 REG_SZ,不会展开环境变量
- 如果需要展开环境变量,系统会自动处理 REG_EXPAND_SZ 类型
- 支持 Unicode 字符串
