[Lazarus] GetAppConfigDir on Windows XP (PT-BR): Configura??es
Bart
bartjunk64 at gmail.com
Fri Apr 1 23:03:14 CEST 2016
On 4/1/16, Denis Kozlov <dezlov at gmail.com> wrote:
> Yes, Lazarus 1.7 uses SHGetFolderPath directly. Lazarus 1.6 fixes branch
> still uses GetWindowsSpecialDir.
>From the 1.6 fixes brach, file
($lazarus)/components/lazutils/winlazfileutils.inc
This happens in the initialization section when Windows version > WinMe:
_GetAppConfigDirUtf8 := @GetAppConfigDirWide;
function GetAppConfigDirWide(Global: Boolean; Create: boolean = false): string;
const
CSIDL_GLOBAL = {$IFDEF
WINCE}CSIDL_WINDOWS{$ELSE}CSIDL_COMMON_APPDATA{$ENDIF WINCE};
CSIDL_LOCAL = {$IFDEF WINCE}CSIDL_APPDATA{$ELSE}CSIDL_LOCAL_APPDATA{$ENDIF};
begin
If Global then
Result := GetWindowsSpecialDirW(CSIDL_GLOBAL)
else
Result := GetWindowsSpecialDirW(CSIDL_LOCAL);
...
And GetWindowsSpecialDirW is also in winlazfileutils.inc:
function GetWindowsSpecialDirW(ID : Integer) : String;
Var
APath : Array[0..MAX_PATH] of WideChar;
WS: WideString;
Len: SizeInt;
begin
Result := '';
if (CFGDLLHandle = 0) then
InitDLL;
If (SHGetFolderPathW <> Nil) then
begin
FillChar(APath{%H-}, SizeOf(APath), #0);
if SHGetFolderPathW(0,ID or CSIDL_FLAG_CREATE,0,0, at APATH[0]) = S_OK then
begin
Len := StrLen(APath);
SetLength(WS, Len);
System.Move(APath[0], WS[1], Len * SizeOf(WideChar));
Result := AppendPathDelim(Utf16ToUtf8(WS));
end;
end
else //note: only on Windows < XP
Result := SysToUtf8(GetWindowsSpecialDir(ID));
end;
And SHGetFolderPathW is initialized like this:
Pointer(ShGetFolderPathW):=GetProcAddress(CFGDLLHandle,'SHGetFolderPathW');
So, also on the 1.6 branch we directly call the Windows Wide API
(provided you are NOT on a Win9x system).
I showed you the revision, you can read that I implemented it that
way, so why do you think it's not true what I'm telling you?
This was introduce way before the 1.6 was branched off.
I tested it with unicode characters (some oriental characters) outside
my system codepage (western european) and it works as expected.
Note:
Mattias renamed GetWindowsSpecialDirW into SHGetFolderPathUTF8 and
exposed it in the interface section of LazFileUtils.
Bart
More information about the Lazarus
mailing list