An extremely useful and code cutting solution. Much appreciated Peter!

function Ansi2Uni(st) blen = (String.Length(st)*2)+2 wbuf = Memory.Allocate(blen) _st = Memory.Allocate(String.Length(st)) Memory.PutString(_st, st, -1, "UTF8") DLL.CallFunction("kernel32.dll", "MultiByteToWideChar", "0, 0, ".._st..", -1, "..wbuf..", "..blen, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL) Memory.Free(_st) return wbuf end function Uni2Ansi(Uni) size = DLL.CallFunction("kernel32.dll", "WideCharToMultiByte", "0, 0, "..Uni..", -1, 0, 0, 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL) heap = DLL.CallFunction("kernel32.dll", "GetProcessHeap", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL) ansi = tonumber(DLL.CallFunction("kernel32.dll", "HeapAlloc", heap..", 8, "..size, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)) DLL.CallFunction("kernel32.dll", "WideCharToMultiByte", "0, 0, "..Uni..", -1, "..ansi..", "..size..", 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL) local ret = Memory.GetString(ansi, -1, "UTF8") Memory.Free(ansi) return ret end
Text = Ansi2Uni("Hello World") Caption = Ansi2Uni("Test") DLL.CallFunction("user32.dll", "MessageBoxW", Application.GetWndHandle()..", "..Text..", "..Caption..", 0", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL)
Comment