zhouying82
高階會員
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:150 回覆:272 積分:189 註冊:2004-03-16
發送簡訊給我
|
是我从其他的地方转发的。 问题: 如何读取注册表里面的特殊类型的名称, 如: 类型: 0x3ed
怎么才能得到 0x3ed这个值
| 来自: 地质灾害 时间: 2007-8-21 9:40:15 ID: 3825192 | 注册表键值类型有以下几种:
REG_SZ 字符串
REG_MULTI_SZ 多行字符串,每行字符串以NULL字符结尾,最后一行以两个NULL字符结尾
REG_EXPAND_SZ 可扩充字符串 字符串中包含了环境变量,比如%systemroot%
REG_DWORD 双字
REG_BINARY 二进制序列
你所说的0x3ed应该是DWORD值了。
这是我写的一个函数,函数中直接调用API读取注册表,没有用到Delphi的封装类:
function RegReadInteger(KeyName, Name: string; RootKey: HKEY =
HKEY_LOCAL_MACHINE): Integer;
var
hReg: HKEY;
cbType, cbResult: DWORD;
begin
try
cbType := REG_NONE;
if (RegOpenKeyEx(RootKey, PAnsiChar(KeyName), 0, KEY_QUERY_VALUE, hReg) <>
ERROR_SUCCESS)
or (RegQueryValueEx(hReg, PChar(Name), nil, @cbType, @Result, @cbResult)
<> ERROR_SUCCESS)
or (cbType <> REG_DWORD) then
Result := 0;
finally
RegCloseKey(hReg);
end;
end;
| 来自: 外来天客 时间: 2007-8-21 9:45:16 ID: 3825194 | 我要读取的是它的类型..不是要它里面的值. 0x3ed 这是一种类型..就如: DWORD, 字符串 二进制...
| 来自: 地质灾害 时间: 2007-8-21 11:12:52 ID: 3825265 | lz没看代码?bs一下!我的函数不是既读出了类型又读出了值么?你以为代码中的cbType是什么了?如果只想获取类型值,改良一下代码就可以了:
function RegGetValueType(KeyName, Name: string; RootKey: HKEY =HKEY_LOCAL_MACHINE):DWORD;
var
hReg: HKEY;
begin
try
if (RegOpenKeyEx(RootKey, PAnsiChar(KeyName), 0, KEY_QUERY_VALUE, hReg) <>
ERROR_SUCCESS)
or (RegQueryValueEx(hReg, PChar(Name), nil, @cbType, nil, nil)
<> ERROR_SUCCESS) then
Result := REG_NONE;
finally
RegCloseKey(hReg);
end;
end;
类型值是DWORD型,其描述可以在msdn中找到:
REG_BINARY Binary data in any form.
REG_DWORD A 32-bit number.
REG_DWORD_LITTLE_ENDIAN A 32-bit number in little-endian format.
Microsoft® Windows® is designed to run on little-endian computer architectures. Therefore, this value is defined as REG_DWORD in the Windows header files.
REG_DWORD_BIG_ENDIAN A 32-bit number in big-endian format.
Some UNIX systems support big-endian architectures.
REG_EXPAND_SZ Null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions. To expand the environment variable references, use the ExpandEnvironmentStrings function.
REG_LINK Reserved for system use.
REG_MULTI_SZ Array of null-terminated strings, terminated by two null characters.
REG_NONE No defined value type.
REG_QWORD A 64-bit number.
REG_QWORD_LITTLE_ENDIAN A 64-bit number in little-endian format.
Windows is designed to run on little-endian computer architectures. Therefore, this value is defined as REG_QWORD in the Windows header files.
REG_SZ Null-terminated string. It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.
| 来自: 外来天客 时间: 2007-8-21 12:58:01 ID: 3825318 | 自己也写了一个
其实很简单的.只是当时没能想到
var
Rf : TRegistry;
DataType,c: integer;
begin
...
Rf := TRegistry.Create ;
Rf.RootKey := HKEY_LOCAL_MACHINE;
Rf.OpenKey('..............................................', False);
RegQueryValueEx(Rf.CurrentKey,'', nil, @DataType, nil, @c); //读取默认值类型
ShowMessage(Format('%0.8x',[DataType]));
Rf.Free;
...
|
------ 断断续续的学了几年,还是一个初学者,永远支持Delphi !
|