Thanks Remy - I wasn't notified of your reply for some reason, but it's what I came to as well. Basically all the structs, types and methods that can be either ANSI or Wide points to the ANSI version in the RTL. So, to make things work, I have to explicitly call the "W" versions of the methods and use the "wide" types based on my "build mode".
This, although a bit "cumbersome" (lots of {$IFDEFS}), works well now. String handling on the other hand is still not solved.
I'm trying to twist my mind info finding a way to basically disable implicit codepage conversion, or at least prevent it - but I haven't yet seen the light. Using the LazUTF8 isn't really an option since I need the "ANSI version" of the DLL to leave the everything in its codepage encoding. At the same time, I need the "Wide version" to maintain whatever Unicode information it comes across. I would also prefer to keep the DLL as small as possible, and not include anything that isn't strictly necessary.
Since "everything" in FPC seems to be built around "8 bit strings", it would seem logical for me to convert everything between UTF-8 and UTF-16 very close to the Win API calls, and then use normal string handling internally. But, the same code (except the conversion UTF16/UTF8 conversion which would happen within ifdefs) would also need to deal with the system codepage encoded ANSI strings. This would all work out nicely as far as I can tell if I could prevent implicit conversion, since I'm not going to go down the rabbithole of string sorting etc.
But, there must be something fundamental I'm missing with the logic surrounding the code page handling. I get that you can define a string type to "be" a certain code page at compile time (type somestring : string(CP_XX)) - but I can hardly imagine when that's useful. Controlling the codepage at runtime seems harder - if you just use AnsiString I understand it if its codepage is initially "CP_ACP". But, since an empty string is just a null pointer, you can't actually set the codepage for an empty string (before you put something in it). If you first assign something to it and then set the codepage (and does a conversion), the implicit conversion has already taken place as far as I understand - and information might already be lost.
At this point I'm seriously wondering if I have to resort to just using PChar/PWideChar or similar, and do all string processing using own implementations or using Win API calls. But, I would really, really prefer not to have to go that way.
PS! It's quite "strange" for me that Remy Lebeau replies to me. In my world I guess you're some kind of celebrity or something ;P I used to read a lot of what you wrote in relation with the Indy components some 20+ years ago, and considered you to be pretty close to the allmighty