String To unicode String lazarus / 21-General ---------------------------------------------------------------------- Weitentaaal · 2021-03-12 08:53 Hello Guys Rewriting some vb6 Code in lazarus. So here is my issue: I Have a Function in a DLL wich recieves a Unicode String and returns a Unicode String. Simple i thought... 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        //JZa := StrConv(JZa, vbUnicode);  --> vb6      //JZa2 := StrConv(JZa2, vbUnicode);--> vb6      //JZaRueckgabe := StrConv(ZAJsonRequestBSTR(JZa), vbFromUnicode);--> vb6            ShowMessage(JZa);       Temp := UTF8Decode(JZa);       ShowMessage(Temp);        //JZaRueckgabe := UTF8Encode(DLLAufrufe.Call_ZAJsonRequestBSTR(UTF8Decode(JZa)));      Temp := DLLAufrufe.Call_ZAJsonRequestBSTR(UTF8Decode(JZa));      ShowMessage('Unicode : ' + Temp + Char(13) + ' -------------- ' + Char(13) + 'Ansi String : ' + UTF8Encode(Temp));  This Code Doesn't work so i wanted to ask u Guys if u have a better Solution. Thanks ---------------------------------------------------------------------- balazsszekely · 2021-03-12 09:11 @Weitentaaal QuoteThis Code Doesn't work so i wanted to ask u Guys if u have a better Solution. Before FPC 3.0.0 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 uses LazUTF8; procedure TForm1.Button1Click(Sender: TObject);var  U_JZA, U_JSON: UnicodeString;  JZA, JSON:  String;begin  U_JZA := UTF8ToUTF16(JZa);  U_JSON := DLLAufrufe.Call_ZAJsonRequestBSTR(UJZa);  JSON := UTF16ToUTF8(U_JSON);end;  After FPC 3.0.0: 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 var  U_JZA, U_JSON: UnicodeString;  JZA, JSON:  String;begin  U_JZA := JZa;  U_JSON := DLLAufrufe.Call_ZAJsonRequestBSTR(UJZa);  JSON := U_JSON;end; It should work without typecast, but to be absolutely sure you can write: U_JZA := UnicodeString(JZa) /  JSON := String(U_JSON). ---------------------------------------------------------------------- Weitentaaal · 2021-03-12 09:24 Used UTF8Decode --> didn't worked Used UTF8ToUTF16 --> didn'T work im pretty Sure Unicode(String) wont work either ---------------------------------------------------------------------- balazsszekely · 2021-03-12 09:37 @Weitentaaal QuoteUsed UTF8Decode --> didn't worked Used UTF8ToUTF16 --> didn'T work im pretty Sure Unicode(String) wont work eitherI used UnicodeString/WideString for api calls many many times and I'm pretty sure it works.  Looking at your api name "ZAJsonRequestBSTR", more exactly at "BSTR" part, it reminds me that the proper string type to use is WideString, which is a COM compatible not reference counted string. ---------------------------------------------------------------------- Weitentaaal · 2021-03-12 10:00 I Guess it should work then. tryed that ang got Access Violation. Not the result i wanted but i think the Conversion works. New Problem now is that i don't know where this Access violation gets raised  xD But Thnaks GetMem ---------------------------------------------------------------------- PascalDragon · 2021-03-12 14:36 How is your Call_ZAJsonRequestBSTR declared? If it's UnicodeString then you need to change it to WideString cause the BSTR compatible type is WideString, not UnicodeString.