Wrong utf8 chars in Windows 11 lazarus / 34-Windows ---------------------------------------------------------------------- bigeno · 2021-10-25 11:37 I need help, on windows xp,7,10 all is ok but on windows 11 I'm getting wrong utf8 chars in my app. I've my strings in dll and I import my strings with LoadString function. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    buffer : array[0..512] of char;   res: string;    if langDLL = dynlibs.NilHandle then exit;   k:=LoadString(langDLL,i,buffer,sizeof(buffer));   SetString(Res,buffer,k);  can you help with this problem ? ---------------------------------------------------------------------- AlexTP · 2021-10-25 11:55 Can you provide the compilable project? ---------------------------------------------------------------------- Mr.Madguy · 2021-10-25 12:55 May be your resources are stored in Unicode? ---------------------------------------------------------------------- bigeno · 2021-10-25 13:14 Quote from: Mr.Madguy on October 25, 2021, 02:55:30 pmMay be your resources are stored in Unicode? they are saved same as the project in utf8.  And strings from project source are ok, only from my dll resource. But on windows < 11 all is ok. So something was changed in windows user32 for win11 ?? function LoadString(hInstance:HINST; uID:UINT; lpBuffer:LPSTR; nBufferMax:longint):longint; external 'user32' name 'LoadStringA'; ---------------------------------------------------------------------- wp · 2021-10-25 14:08 It is working for me when I create the res file by specifying the codepage of my system: Code: [Select]windres.exe -c 1252 -i .\texts.rc -o .\texts.res Never worked with these resource utils... https://sourceware.org/binutils/docs/binutils/windres.html says: Quote-c val --codepage val     Specify the default codepage to use when reading an rc file.Since the rc file in UTF8 I'd have expected that the codepage should be specified as 65001 (UTF8). Strange... Maybe it would be clearer if there were a "W" version of LoadString function. ---------------------------------------------------------------------- bigeno · 2021-10-25 14:12 Quote from: wp on October 25, 2021, 04:08:12 pmIt is working for me when I create the res file by specifying the codepage of my system: Code: [Select]windres.exe -c 1252 -i .\texts.rc -o .\texts.res Never worked with these resource utils... https://sourceware.org/binutils/docs/binutils/windres.html says: Quote-c val --codepage val     Specify the default codepage to use when reading an rc file.Since the rc file in UTF8 I'd have expected that the codepage should be specified as 65001 (UTF8). Strange... Maybe it would be clearer if there were a "W" version of LoadString function. omg, thx, it works on win11 with 1252 here. But file is utf8... ---------------------------------------------------------------------- bigeno · 2021-10-25 14:14 But now there is problem on windows 10... ---------------------------------------------------------------------- AlexTP · 2021-10-25 14:15 >Maybe it would be clearer if there were a "W" version of LoadString function. Can you use LoadStringW instead? ---------------------------------------------------------------------- wp · 2021-10-25 14:26 Quote from: bigeno on October 25, 2021, 04:14:07 pmBut now there is problem on windows 10... I'm afraid, doing the Win 11 upgrade yesterday was more destructive than what I thought... ---------------------------------------------------------------------- bigeno · 2021-10-25 16:40 I just simple change to LoadStringW and nothing. It seems that the problem is with resources (windres<->win11). At least I can temporarily provide a patch dedicated for win11 for my application with -c 1252. However, I completely don't understand why 1252 when my system have 1250. magic... ---------------------------------------------------------------------- wp · 2021-10-25 16:50 Did you try creating the res file with lazres (in folder tools of your Lazarus installation)? I use it a lot for the palette images and other image resources, but did not yet use it for text resources. There's also an fpcres in the fpc/bin folder. But I'd first give lazres a try because it originates in the UTF8 world of Lazarus... ---------------------------------------------------------------------- Mr.Madguy · 2021-10-26 06:42 Problem is most likely with triple codepage conversion. Fist you have your rc file, that can have different codepages. I guess, resources should be stored in UTF-16. So, conversion is made. Then you call LoadStringA, where they're converted back to Ansi. And then they're converted from Ansi to UTF-8. No wonder, that something can go wrong. Some "default" codepage settings are used at some point, that seem to be different on Win10 and Win11. Try using LoadStringW, but use explicit UTF8Encode. PChars are tricky. Automatic codepage conversion doesn't work for them. ---------------------------------------------------------------------- bigeno · 2021-10-26 12:13 Quote from: Mr.Madguy on October 26, 2021, 08:42:26 amProblem is most likely with triple codepage conversion. Fist you have your rc file, that can have different codepages. I guess, resources should be stored in UTF-16. So, conversion is made. Then you call LoadStringA, where they're converted back to Ansi. And then they're converted from Ansi to UTF-8. No wonder, that something can go wrong. Some "default" codepage settings are used at some point, that seem to be different on Win10 and Win11. Try using LoadStringW, but use explicit UTF8Encode. PChars are tricky. Automatic codepage conversion doesn't work for them. it looks like you're right. I'll have to check it out but I think I can go the "no-encoding way", for example "#e" means ę, etc. That would be the best in that case.