0
votes

i have a delphi 6 COM dll. it has method like dosomething(const LicenceName: Widestring);

when i use this COM from .net csharp like: comdll.dosomething("ğüşiöçĞÜŞİÖÇ"), i get the licenceName param in com dll as "güsiöçGÜSIÖÇ" some turkish character disappears.

what should i do to pass Turkish characters correctly ?

Thanks in advance

1
Both .NET and COM use utf-16 encoded Unicode strings. They can't be the source of the lossage. Suspect a problem with the encoding of the source code file or an unintentional conversion to AnsiString in the Delphi code. Use the debugger. And make sure that the debugger itself isn't the cause.Hans Passant
Seems like a mis-code-paged round-trip, f.i. this: WideCharToMultiByte(1252, 0, #$015F#$0131#$011F, ... will convert the wide string 'şığ' to ansi string 'sig'.Sertac Akyuz
Need to see some sample code (the COM function declaration of the function you are calling via COM).Warren P

1 Answers

0
votes

Delphi 6 string types are natively Ansi (single byte per character). The COM "BSTR" type, and .NET string type are natively Unicode UTF-16 (two bytes per unicode codepoint, most of which correspond to a single character).

If your COM function code in Delphi 6 uses WideString instead of string, you should be able to do your COM function call without an issue. Otherwise, you are falling into a codepage conversion issue, perhaps. It is also possible to convert to a Turkish codepage with ANSIString, but in my opinion such a conversion is happening implicitly in your code, and so you should look for those implicit conversions and remove the mis-use of String (AnsiString), replacing the types with WideString.

There are two ways you could be doing your COM function calll and you didn't specify.

  1. Invocation using OLE Variants.

    var o: OleVariant; ws:WideString; begin o := CreateOleObject('NameThing.OtherThingName'); o.MethodName(ws); // this should work. Note: Do NOT use STRING type here in Delphi 6. end;

  2. Invocation using native COM with a type library. Details of doing this correctly depend on your specific function parameters. You have not specified if you have a MyUnit_TLB.pas unit, but if you have please update the question and show the actual method you're invoking.