Use of "RegQueryValueEx" in your unit "mailtest.pas"

delphi package - automated exception handling

Use of "RegQueryValueEx" in your unit "mailtest.pas"

Postby MartinE » Tue Feb 27, 2018 3:17 pm

Hello Matthias,

while changing my project to Unicode, I found an very small bug in the use of "RegQueryValueEx" in your unit "mailtest.pas". I know that the function is no longer used with the newer operating system. You don't have to change anything, as long as it is in the forum.

Your Code:
Code: Select all
c1 := c1 * 2;

Correct it is:
Code: Select all
c1 := c1 div 2;

or
Code: Select all
c1 := c1 div SizeOf(Char);

Same at:
Code: Select all
SetString(result, p1, c1);

Correct is:
Code: Select all
SetString(result, p1, c1 div 2);


See reference:
EN: http://docwiki.embarcadero.com/RADStudi ... or_Unicode
In RegQueryValueEx, the Len parameter receives and returns the number of bytes, not characters. The Unicode version thus requires twice as large value for the Len parameter.


DE: http://docwiki.embarcadero.com/RADStudi ... e_anpassen


Many greetings

Martin
MartinE
 
Posts: 1
Joined: Tue Feb 27, 2018 3:01 pm
Location: Hargesheim/Niedernhausen, Germany

Re: Use of "RegQueryValueEx" in your unit "mailtest.pas"

Postby madshi » Tue Feb 27, 2018 4:33 pm

Thanks Martin.

The mailtest.pas was written with/for Delphi 7, though, so the call is actually meant to go to RegQueryValueExA, not W.

Your 2nd change is correct for Unicode. But the "c1 := c1 * 2" is actually correct as it is, for either A or W. "c1" is only used as the allocation buffer size, and I'm intentionally allocating twice as much memory as asked for, just to be safe. You can consider it a waste, but since the buffer is only used temporarily, it shouldn't be a problem. I often allocate bigger than asked for in such situations, just as an extra precaution to avoid a possible buffer overrun by 1 byte or such nonsense.
madshi
Site Admin
 
Posts: 9774
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 3 guests