2

I have a regular entry in the [INI]-Section of InnoSetup script

e.g.

[INI]
Filename: "{app}\myinifile.ini"; Section: "MY_SECTION"; Key: "MY_KEY"; String: "value which contains a symbol (§) that is different between ascii and UTF-8 encoding: §" 

Now, on some systems if the INI file is created the paragraph symbol ("§") is handled as ascii which is expected and on other systems it's transformed to UTF-8.

In fact if I analyse the precise content of that files.

Normally I have: § => "47" (hex)
BUT on some systems SOMEHOW: § => "C2 47" (hex), which is the UTF-8 representation of "§"
but why this differences?

I thought Inno Setup uses the regular WritePrivateProfilString from the Win-API. I found this in the Win-Api:

The winbase.h header defines GetPrivateProfileString as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant.

BUT: how can I tell Inno Setup to use always the ANSI variant of it?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Tony
  • 360
  • 2
  • 11
  • I would assume that INNO will respect the encoding on the INI file (if it already exists) and use the correct Write... methods by looking at the BOM. But I don't know the source of Inno. I am sure others will comment. – Andrew Truckle Sep 02 '20 at 16:47
  • Yes, Inno Setup uses `WritePrivateProfileString`. – But the comment you are quoting is about API of the function, not about the encoding of the INI file. It's not relevant to your problem. – In general, I believe that Windows API does not support UTF-8 encoding for INI files. See also [Save INI file in UTF-8 rather than ANSI in Inno Setup](https://stackoverflow.com/q/35117362/850848). And also the question it links: [How to read/write Chinese/Japanese characters from/to INI files?](https://stackoverflow.com/q/204241/850848). – Martin Prikryl Sep 02 '20 at 16:50
  • Also, your quote surely applies to the executable that is bring compiled. It would be an assumption to assume that any INI file you them use with that exe is going to be encoded the same way surely. Going off tack :) I will wait and see what the others say. :) – Andrew Truckle Sep 02 '20 at 16:51
  • @MartinPrikryl INI files do support encoding though, but like this: https://imgur.com/0HTLww9 – Andrew Truckle Sep 02 '20 at 16:54
  • 1
    @AndrewTruckle I corrected my comment to say: *"I believe that **Windows API** does not support UTF-8 encoding for INI files"*. Of course, INI file is a text file, you can use other software to change encoding of the text file to anything you like. But I believe you won't be able to read such INI file correctly with Windows API (and consequently with Inno Setup). What my linked answer says already. – Martin Prikryl Sep 02 '20 at 16:55
  • @MartinPrikryl Yep, that explains it. The type of encoding of the file can't be UTF-8. Like I had to do. https://stackoverflow.com/a/8821555/2287576 – Andrew Truckle Sep 02 '20 at 16:57
  • Thank you for your comments. The precondition was the INI-file does **not exist** at all before installing. After setup routine has performed, with one and the same INI-directive in innosetup script, on some systems I have different encoding for this special character "§" (xC2A7) and this led me to the assumption that the WinApi for WritePrivateProfileString uses internally (for some condition) the WritePrivateProfileStringA and in some cases WritePrivateProfileStringW (That's why I posted the comment of the WinAPI. It's not explainable to me. :-| – Tony Sep 03 '20 at 06:58
  • @MartinPrikryl Just to clarify any misunderstanding: I dont want to have any Unicode letter in my ini file, plain ASCII is sufficient. Goal is just to have the simple Paragraph character § (xA7) and not the Unicode representation of it (xC2A7). – Tony Sep 03 '20 at 07:20
  • Yes, I understand. I just wanted to point out that I find it strange that you get UTF-8 at all. – Did you test if the difference in behaviour is caused by difference in the existing INI file? In other works, do you get consistent behaviour, if the INI file does not exist at all before the installer starts? How else do the systems differ? + Do you run the *same installer binary* on those systems? Or do you build the installer separately for/on those systems? – Martin Prikryl Sep 03 '20 at 07:33
  • Personally I have to specifically create a text file with the right encoding before I use it (in my MFC software apps). – Andrew Truckle Sep 03 '20 at 08:25
  • @AndrewTruckle Yes, thats maybe a good approach, thank you. I even tried to write in a already UTF-8 encoded ini file, but the result was even more strange. :-) I could not reproduce this behavior on my machine there it worked all fine, so as soon as I get the problem PCs on my desk I will investigate more in detail. – Tony Sep 03 '20 at 11:36

1 Answers1

0

Solved it, on another thread, cause you are right, it has nothing directly to do with InnoSetup, see:

https://stackoverflow.com/a/63989920/10934555

Many thanks anyway, InnoSetup rocks :-)

Tony
  • 360
  • 2
  • 11