Board index » cppbuilder » Re: Using Delphi units
Clayton Arends
![]() CBuilder Developer |
Re: Using Delphi units2006-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 |