我正在使用 Delphi XE2 并从 Shell32.dll 导入 SHGetFolderPath。我正在运行 windows vista x64。运行 SHGetFolderPathA 时结果不清楚。
IE:
uses
Windows;
function SHGetFolderPath(hwnd: Cardinal; csidl: Integer; hToken: Cardinal; dwFlags: Cardinal; pszPath: PChar): Cardinal; stdcall;external 'Shell32.dll' name 'SHGetFolderPathA';
Var
Path:Array [0..MAX_PATH] of Char;
AppData:String;
begin
SHGetFolderPath(0,$001A,0,0,@path[0]);
MessageBox(0,Path,'a',0);
end.
结果是:
与使用 SHGetFolderPathW 相比:
使用视窗;
function SHGetFolderPath(hwnd: Cardinal; csidl: Integer; hToken: Cardinal; dwFlags: Cardinal; pszPath: PChar): Cardinal; stdcall;external 'Shell32.dll' name 'SHGetFolderPathW';
Var
Path:Array [0..MAX_PATH] of Char;
AppData:String;
begin
SHGetFolderPath(0,$001A,0,0,@path[0]);
MessageBox(0,Path,'a',0);
end.
结果清楚地说明了我的 AppData 文件夹的路径,没有问题。
当使用 SHGetFolderPathA 在 x32 Vista 上运行相同的代码时,效果很好。
如果有人可以阐明这是为什么?我的印象是“W”api通常用于Unicode机器......?
编辑:
我现在正在使用以下代码,但出现相同的错误:
uses
Windows;
function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWord; pszPath: PAnsiChar): HRESULT; stdcall; external 'SHFolder.dll' name 'SHGetFolderPathA';
var
path: array[0..MAX_PATH] of char;
begin
SHGetFolderPath(0,$001A,0,0, @path[0]);
MessageBox(0,path,'a',0);
end.
最终编辑:
谢谢大家的回复。SHGetFolderPath 的上述声明很好。在查看了所有回复并获取了每个回复中的信息后,我得出了以下结果:
uses
Windows;
function SHGetFolderPath(hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWord; pszPath: PAnsiChar): HRESULT; stdcall; external 'shell32.dll' name 'SHGetFolderPathA';
var
path: array[0..MAX_PATH] of ansichar;
xRes:String;
begin
If SHGetFolderPath(0,$001A,0,0, @path[0]) = S_OK Then Begin
xRes := Path;
MessageBox(0,PWideChar(xRes),'Result',0);
End Else
MessageBox(0,'An error has occurred.','Result',0);
end.
生成的消息框正确显示了我的 AppData 路径的路径。
再次感谢所有回复。