> according to my tests it works, can you make it fail ?
Of course. Try using it with Russian, for example, instead of "12345".
PRIVATE FUNCTION Leftx (BYref cws AS cwstr, BYVAL nChars AS INTEGER) as string
function = LEFT(*cast(wSTRING PTR, cws.m_pBuffer), nChars)
END FUNCTION
DIM cws AS CWSTR = "Дмитрий Дмитриевич Шостакович"
PRINT LEFTx(cws, 3)
Will print ???", which is the expected result since you are returning it as an ansi string.
Believe me. I did lose countless hours trying to find an acceptable solution, but since it is a bug of the compiler, the solution will be to fix the bug.
Anyway, with the current overloads, it works except with SELECT CASE LEFT/RIGHT. I didn't even know because I never have used LEFT and RIGHT with SELECT CASE. Indeed there are easy workarounds: assign it to a variable first, use MID or use **.
I have managed to get an almost total integration with FreeBasic instrinsics. It even works with files, e.g.:
DIM cws AS CWSTR = "Дмитрий Дмитриевич Шостакович"
DIM f AS LONG = FREEFILE
OPEN "test.txt" FOR OUTPUT ENCODING "utf16" AS #f
PRINT #f, cws
CLOSE #f