Текущий архив: 2006.02.26;
Скачать: CL | DM;
Вниз
Strange registry bug Найти похожие ветки
← →
Thaddy (2005-06-30 20:46) [0]Jon send me the following code:
------------
function GetSerialPortNames: string;
var
reg: HKEY;
l,v: PStrList;
n: integer;
begin
l := NewStrList;
v := NewStrList;
reg := RegKeyOpenRead(HKEY_LOCAL_MACHINE, "HARDWARE\DEVICEMAP\SERIALCOMM");
try
RegKeyGetValueNames(reg,l);
for n := 0 to l.Count - 1 do
v.Add(RegKeyGetStr(reg,l.Items[n]));
finally
RegKeyClose(reg);
end;
Result := l.Text;
l.Free;
v.Free
end;
--------------------
//TDK//Here"s his comment, I can reproduce this!
---------------
The result that I expect is:
Result = "COM3"#$D#$A"COM4"#$D#$A"COM2"#$D#$A"COM1"#$D#$A
But one of the registry values is NOT null-terminated (COM4 length is 4, not 5).
I have used "Registry Commander" and "Resplendent Registrar" to confirm this.
So I get unexpected results, such as these:
Result = "COM3"#$D#$A"COM42"#$D#$A"COM2"#$D#$A"COM1"#$D#$A
Result = "COM3"#$D#$A"COM4\Dev""#$D#$A"COM2"#$D#$A"COM1"#$D#$A
Result = "COM3"#$D#$A"COM4M4$"#$D"1"#$D#$A#$D#$A"COM2"#$D#$ A"COM1"#$D#$A
Result = "COM3"#$D#$A"COM4(003)"#$D#$A"COM2"#$D#$A"COM1"#$D #$A
Result = "COM3"#$D#$A"COM4Ü"#$D#$A""COM2"#$D#$A"COM1"#$D#$A
When I try similar code with the VCL,
---------------------
v.Add(reg.ReadString(l[n]));
---------------------
results are always correct.
Is this a bug in KOL or I am using it incorrectly?
I have tried using RegKeyGetBinary but I don"t know how to use it - I don"t really understand pointers and buffers.
The registry key is automatically re-created when Windows starts and is always the same.
Many thanks in advance.
-------------------------
← →
ECM © (2005-07-01 11:02) [1]Я не совсем понял проблему... но может быть поможет реально работающий кусок кода (из wTerm) - там проблем мною не замечено...:
---------
procedure TSetForm.SetCheckHdw(const Value: Boolean);
var
i: Integer;
RKey: HKEY;
ComList,RegList: PStrList;
S: String;
begin
if fCheckHdwr <> Value then begin
fCheckHdwr := Value;
cbCheckHdwr.Checked := Value;
// COM-Ports Enums
cbComName.Clear;
if fCheckHdwr then begin
RKey := RegKeyOpenRead(HKEY_LOCAL_MACHINE,"HARDWARE\DEVICEMAP\SERIALCOMM");
if RKey <> 0 then begin
RegList := NewStrList();
ComList := NewStrList();
if RegKeyGetValueNames(RKey,RegList) then begin
for i:=0 to RegList.Count-1 do begin
S := RegKeyGetStr(RKey,RegList.Items[i]);
if S <> "" then ComList.Add(S);
end;
end;
if ComList.Count>0 then begin
ComList.Sort(FALSE);
for i:=0 to ComList.Count-1 do begin
cbComName.Items[i] := ComList.Items[i];
end;
i := ComList.IndexOf(ComName);
cbComName.CurIndex := i;
end;
Free_And_Nil(RegList);
Free_And_Nil(ComList);
RegKeyClose(RKey);
RKey := 0;
end;
------
← →
ECM © (2005-07-01 17:25) [2]2Thaddy: а как удалось получить в реестре "one of the registry values is NOT null-terminated"
Страницы: 1 вся ветка
Текущий архив: 2006.02.26;
Скачать: CL | DM;
Память: 0.47 MB
Время: 0.028 c