The problem is that it is not even getting to the systoutf8 function, the function SHGetSpecialFolderPathW(0, SpecialPath, CSIDL, False) is returning FALSE, and the error being reported is 'The System Cannot find the path specified'.
Why don't you just test with the working function provided by GetMem? Why must you modify it first?
[Edit] Ok, I saw you had tried it as-is first. Why the WinAPI function returns FALSE is a mystery then.
Just to be sure: You use default settings in Lazarus, right?
It is possible to disable the default Unicode support by -dDisableUTF8RTL as explained here:
http://wiki.freepascal.org/Lazarus_with_FPC3.0_without_UTF-8_mode... although even it should not affect the value returned from WinAPI.
I have tried using WinCPToUTF8 but this has no change in that the error is prior to this.
Uhhh, no! For some reason you fail to understand the fundamentals.
With the current Unicode support in Lazarus you practically
never need explicit conversion functions.
No SysToUTF8, no WinCPToUTF8, no AnsiToUTF8, nothing.
FPC 3.0+ has dynamic string encodings. Data is converted automatically when it is assigned.
The only exception is when you
really must use Windows system codepages, but in your case it is not necessary.
When you use only Unicode, things go smoothly.
wp and others, please don't recommend system codepages to him or anybody else.