Is it possible I have found a bug in Lazarus Trunk?
function GetSpecialFolder(const CSIDL: Integer): WideString;
...
Result := SysToUTF8(SpecialPath)
No, you added the bug all by yourself. Instead of using the working code provided by GetMem, you added a conversion that is doomed to fail. Why?
You should know the W(ide) versions of WinAPI, like SHGetSpecialFolderPathW, work with Unicode, UTF-16.
That is why the parameter SpecialPath is PWideChar.
GetMem and everybody: I think the return type of your function should be UnicodeString instead of WideString. WideString should be used only with OLE programming.
The problem you are having josh, is that most versions of Windows DO NOT "speak" UTF8/16, or even necessarily Unicode correctly. You will need to ensure that any strings passed to Windows API functions are converted to old-fashioned ASCII code strings.
That is not correct. The WinAPI functions that work with old-fashioned ANSI strings do
not work with Lazarus Unicode system. You must use the W versions that work with Unicode.
Please don't spread false information.
Unicode should be used everywhere in any case because ANSI <-> Unicode string conversions are lossy. The old ANSI string support can be seen as a historical remain, retained only for backwards compatibility.
Unicode in Lazarus + WinAPI are explained here:
http://wiki.freepascal.org/Unicode_Support_in_Lazarus#Calling_Windows_API