AS, you better put this question on the rsdn.ru forum, I think that they are more liberal for beginners than DelphiMasters.
Gu, basically, you should just read the manuals in Delphi XE2. All this is there, just read with thoughts and attention.
1) You must NOT create a DLL. You have to do a BPL. The DLL is designed to work with a simple C interface, such as the Win32 API. These are the most primitive types without any side effects. C is called "machine-independent" assembler for its primitiveness, and the DLL interface is a kind of.
DLLs can be used for compatibility with other languages because they use other side effects incompatible with Delphi. Then the DLL provides the most primitive collaboration, with all the side effects removed from the interface. By lowering the level of interconnects with most simplified types, the DLL provides compatibility.
But when you need to interact with Delphi in Delphi, you better let Delphi take care of all compatibility issues. this is what BPL is made for Delphi 3. There is no reason to use a DLL for this.
Of course, you can shoot in the foot if you like. https://forums.embarcadero.com/thread.jspa?threadID=64114
2) Instead, you should not use WideString in XE2, but UnicodeString. Particular attention is paid to line guides. It sounds like you just haven't read the manuals.
3) String constants are in Unicode. (but the char constants are in ... in ANSI or in Unicode in random order, which leads to errors in operation). And there is no need to ask and trust any words - just open your exe in any viewer and find these constants, you will find them in UCS-2 encoding (aka WideChar) with 2 bytes.
4) The Unicode specification is used to determine the byte order of the processor, whether it is an Intel or Motorola mod. When you are developing for Windows, you can only have Intel byte order, so no specification is needed.
5) the whole paragraph that you wrote about the lengths and sizes of the memory is very ambiguous. What do you mean by length, in what units it is measured, where do you get it from?
I assume that by length you mean the number of characters that do not include any service structures / “behind the hood” characters. This is how the built-in System.Length function (string or array) is returned. However, if this assumption is incorrect, the answer below also becomes incorrect.
And the question, if you have to multiply by 2, is just a sign of bad code. You should always multiply by something, many years ago you should already multiply. Multiply ... what? Using the SizeOf (char -variable) or SizeOf (char) parameter. Then t will be Delphi, which will automatically determine how much memory is needed. And when dealing with a C-string, you should not use length, but length + 1 - do not forget about terminator # 0.
6) How should we work with ANSI strings in different Windows code pages? If we get an ANSI string with code page 1200, do we need to transcode the string or work with it as is?
RTFM !!! Just declare an AnsiString type with code page 1200. or use RawByteStrnig and SetCodePage. Read this code below.
Again, RTFM is what ALL is described in the on-line help. It only takes 2 hours to read it ALL in the built-in help of Delphi XE2.
7) how should we use the TEncoding class to convert between Unicode, UTF-8, WideString and AnsiString classes? TEncoding is for a TStringList or something like that. Why should you? There is a UTF8String type - just use it.
var as: AnsiString; ucs2s: string; utf8string: UTF8String; ... as: = ucs2; utf8s: = as; ....
8) Are there any serious performance penalties using wide strings or Unicode strings? It depends on which Unicode you mean, UCS-2 or UTF8. And what operations do you want to use. Just do a looong loop and measure the time.
9) Do we have to write our interfaces to require length parameters for the parameter types PChar, PAnsiChar and PWideChar? It is your choice, do as you wish. Typically, PChar is a C-line ending with # 0. This is how the StrLen function works. If you ignore this convention and use it as an untypes Pointer, then skip the length separately.
EVERYTHING, this question has already been answered to help !!! Just read it.
function CDF_File_Buffer.GetStringNoBounds(const ofs, len: integer): string; // , var cntDOS, cntWin, cntWeird, i : Cardinal; sBuf: RawByteString; cp: word; ptr, ptr_i: PAnsiChar; const rusDOS: set of AnsiChar = [