- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am writing a 40 character variable to the registry using:
iSt = RegSetValueEx(hKey, sValueName, 0, REG_SZ, loc(sValue), iLen)
However sValue (length 40) may contain char(0) bytes, it is an encrypted string. iLen is 40.
The call is only writing to the registry variable up to one character before the char(0), as it is thinking it is NULL terminated. How do I get it write the full 40 character variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lpData
The data to be stored.
For string-based types, such as REG_SZ, the string must be null-terminated. With the REG_MULTI_SZ data type, the string must be terminated with two null characters.
Use REG_MULTI_SZ type and double terminate
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lpData
The data to be stored.
For string-based types, such as REG_SZ, the string must be null-terminated. With the REG_MULTI_SZ data type, the string must be terminated with two null characters.
Use REG_MULTI_SZ type and double terminate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To write arbitrary binary data to a registry value (which is what you have if your encryption method spits out null characters), use REG_BINARY as the type. The type of data being written to the registry is here a separate concept from the type of the variable being used to manipulate the data in your Fortran program.
(If you use REG_MULTI_SZ, then one day your encryption method will spit out two null characters in a row, and the problem will reoccur (note also the API requires double null termination for REG_MULTI_SZ - do you ensure that?). Because you've said the data is a string (i.e. a sequence of characters that humans can "read") it is also be subject to code page translation on the way in and out of your very-likely-not-unicode application. Beyond null characters, does your encryption method guarantee that the "string" is a valid multibyte sequence in the current code page ? How will the application respond to a later change in code page once the registry key has been written?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your last point of 2 null characters in a row came into in mind during my walk, and I was going to post the question when I got back, but you beat me to it! So if I use REG_BINARY will that get also around the code page issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had not appreciated that you were not writing "text" data , REG_BINARY is arbitrary binary data in any form. The interpretation of that data when you read it back is your responsibility, you shouldl get back exactly what you put there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, REG_BINARY is just what I am looking for.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page