-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 2014-10-12 19:47, schrieb Jonathan Vollebregt:
I don't free the old string. Because the function handles more than one type of data the caller has to free the data when it's done - if I don't copy the string it will end up freeing one of it's own parameters.
I used bad terminology here. What I meant was that wchar_get_data could operate on the input memory instead of copying it first since the original data is not needed after the call.
Of course further features may require that the input remains untouched. Is this the case?
There's another ugliness though: If the input string is "0", replacing it with a 4-byte DWORD just works because it is a WCHAR that consists of two two bytes elements. I don't know about other data types - they may actually grow.
Sorry, this seems confusing without comments. The REG_MULTI_SZ stores multiple strings in the registry: nil separated with a double nil to end the array.
When reading from the registry simply replacing the nil's with ',' seems the simplest way to do it, and that's exactly wine's regedit's behaviour. I'm not sure what the native behaviour is supposed to be though.
As I mentioned tests would be a good idea :-) .
I understood what the function was doing after enough reading. What I meant was that there was probably a nicer way to implement the same behavior. E.g. if you do the character replace in the existing string you could write this as
for (i = 0; inout[i] || input[i + 1]; i++) { if (!inout[i]) inout[i] = ','; }
Or MakeMULTISZDisplayable() from regedit. MakeMULTISZDisplayable is probably faster because it does only one comparison per character.
But if you cannot operate on the input data that idea is moot. You could copy first and then run a second iteratation over the string, but I think that results in worse performance than your code.
If the separator has been left out of the commandline, the separator variable here will be 0. By default reg (From everything I've read) interprets "\0" as the separator - that is it takes an escaped nil as it's input to split the strings.
If you *do* supply a separator variable though it will split by that, so the following commands should have an equivalent effect:
reg add HKCU /v test /t REG_MULTI_SZ /d "string\0morestring" reg add HKCU /v test /t REG_MULTI_SZ /s "#" /d "string#morestring"
You mean it uses a two-byte separator '\','0', rather than the one-byte separator '\0'? In this case it would be best to make the code work on generic string separators. The default separator needs tests as well.