- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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?)
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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?
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Thanks, REG_BINARY is just what I am looking for.
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite