Board index » cppbuilder » Re: Using Delphi units

Re: Using Delphi units


2006-10-02 12:27:47 AM
cppbuilder36
There is a minor problem in the functions. There is an extremely slight
chance that 'Result' or 'Name' can be modified by an external source before
the call to RegQueryValueEx() or RegSetValueEx() returns. This would happen
if you use threads and you are using those variables in another thread.
Like I said, very remote chance but I would like to correct the code for
posterity.
bool ReadMultiString(TRegistry* Reg, String const& Name, String& Result)
{
Result.SetLength(0);
String name = Name;
DWORD dataType;
DWORD dataSize;
if (RegQueryValueEx(Reg->CurrentKey, name.c_str(), NULL, &dataType,
NULL, &dataSize) != ERROR_SUCCESS ||
dataSize == 0 || dataType != REG_MULTI_SZ)
return false;
String tmpString;
tmpString.SetLength(dataSize);
if (RegQueryValueEx(Reg->CurrentKey, name.c_str(), NULL, &dataType,
tmpString.c_str(), &dataSize) != ERROR_SUCCESS)
throw ERegistryException(Rtlconsts_SRegGetDataFailed,
OpenArray<TVarRec>(name), 0);
Result = tmpString;
return true;
}
void WriteMultiString(TRegistry* Reg, String const& Name,
String const& Value)
{
String nulStr('\0');
String name = Name;
String value = Value + nulStr + nulStr;
if (RegSetValueEx(Reg->CurrentKey, name.c_str(), 0, REG_MULTI_SZ,
value.c_str(), value.Length()) != ERROR_SUCCESS)
throw ERegistryException(Rtlconsts_SRegSetDataFailed,
OpenArray<TVarRec>(name), 0);
}
- Clayton
 
 

Re:Re: Using Delphi units

Thank you Ed, it works nicely.
Regards, Abraham
 

Re:Re: Using Delphi units

The name's Clayton ... and you're welcome!
- Clayton
 

{smallsort}

Re:Re: Using Delphi units

At 23:23:23, 01.10.2006, Clayton Arends wrote:
Quote
The name's Clayton ... and you're welcome!

- Clayton
Well, what's in a name, after all? <eg>
--
Rudy Velthuis [TeamB] rvelthuis.de/
"The years of peak mental activity are undoubtedly between
the ages of four and eigh{*word*249}. At four we know all the
questions, at eigh{*word*249} all the answers." -- unknown
 

Re:Re: Using Delphi units

"Clayton Arends" < XXXX@XXXXX.COM >wrote in news:452031c0
$ XXXX@XXXXX.COM :
Quote
The name's Clayton ... and you're welcome!
Sorry Clayton. Since Ed also said complicated things I confused you with
him :)
Regards, Abraham