Andy Groom
Andy Groom

Reputation: 629

How to write a string containing ascii codes into the Registry?

I need to write the following value into the Registry during setup:

[Registry]
Root: HKCU; Subkey: "Software\Apt\TCM\Tables\Standard"; ValueType: string; ValueName: "Campaign planner"; ValueData: "Sent letter #1¦TOGGLE:TICK2¦1500\01Follow-up call¦TOGGLE:TICK2¦1500\01¦SPACE¦45\01Sent letter #2¦TOGGLE:TICK2¦1500\01Follow-up call¦TOGGLE:TICK2¦1500\01¦SPACE¦45\01Notes¦¦4000"

but where it says "\01" I need to write ASCII character 01, so it would be entered like this:

enter image description here

How can I do this?

Upvotes: 1

Views: 496

Answers (1)

TLama
TLama

Reputation: 76713

One way might be replacing all the occurences of the \01 sequence by the StringChange function at compilation time. Though I couldn't find a way how to escape the SOH (ASCII char 1) without turning off the Pascal style string literals, this will do the job:

#pragma parseroption -p-

[Registry]
...; ValueData: "{#StringChange('Lorem ipsum\01dolor sit amet', '\01', '\x01')}"

However, the code above looks to me overcomplicated. If you don't mind that all the backslash escaped chars will evaluate to their corresponding chars, you may define a variable that will escape them:

#pragma parseroption -p-
#define MyValue "Lorem ipsum\01dolor sit amet"

[Registry]
...; ValueData: "{#MyValue}"

But note that it applies to all backslash escaped chars, like \02, \03 and all their respective notations, which might not always fit to your constant value.

Still, as the most reliable way I'm finding to use the code section with its StringChangeEx function.

Upvotes: 1

Related Questions