32位程序在64位系统下读取注册表异常:IDE内正常外部运行失败
自定义注册表整数读取函数问题
背景
使用TRegistry对象时,32位程序在64位系统中读取注册表整数的返回值最大仅为10000,无法获取正确结果,因此自定义了LB_ReadRegistryInteger函数来兼容32/64位Windows系统。但该函数在IDE内运行可返回正确值,脱离IDE独立运行则读取失败。
函数代码
function LB_ReadRegistryInteger(strSubKey: String; strValueName: String): Integer; // ***************************************************************************** // 本函数用于读取注册表中指定键的整数值,兼容32位和64位Windows系统 // ***************************************************************************** const const_KEY_WOW64_64KEY = $000000100; // KEY_WOW64_64KEY 常量值 var Key: HKey; // 注册表键句柄 TheInt: Integer; // 存储读取到的整数值 IntSize: Integer; // 整数数据的大小 TheType: Integer; // 待读取的数据类型 begin Result := 0; // 默认返回值(读取失败时返回0) TheType := REG_DWORD; // 指定读取DWORD类型数据 IntSize := SizeOf(TheInt); // 设置整数数据的大小 // 尝试打开注册表键并读取值 if RegOpenKeyEx(HKEY_LOCAL_MACHINE,PChar(strSubKey),0 ,(KEY_READ or const_KEY_WOW64_64KEY),Key) = ERROR_SUCCESS then if RegQueryValueEx(Key,PChar(strValueName),nil ,@TheType,@TheInt,@IntSize) = ERROR_SUCCESS then Result := TheInt; // 读取成功则返回获取到的值 RegCloseKey(Key); // 关闭注册表键 end; // LB_ReadRegistryInteger
调用示例
// 读取GDIProcessHandleQuota值 TheValue := LB_ReadRegistryInteger('\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows' ,'GDIProcessHandleQuota');
内容的提问来源于stack exchange,提问作者Steve
相关产品推荐
相关产品推荐

