请问SHParseDisplayName这个函数怎么用
需要从文件路径获取外壳文件路径。
查询MSDN,找到SHParseDisplayName这个函数。函数说明如下:
Syntax
HRESULT SHParseDisplayName( LPCWSTR pszName,
IBindCtx *pbc,
PIDLIST_ABSOLUTE *ppidl,
SFGAOF sfgaoIn,
SFGAOF *psfgaoOut
);
Parameters
pszName
[in] Pointer to a zero-terminated wide string that contains the display name to parse.
pbc
[in] A bind context that controls the parsing operation. This parameter is normally set to NULL.
ppidl
[out] Address of a pointer to a variable of type ITEMIDLIST that receives the item identifier list for the object. If an error occurs, then this parameter is set to NULL.
sfgaoIn
[in] A ULONG value that specifies the attributes to query. To query for one or more attributes, initialize this parameter with the flags that represent the attributes of interest. For a list of available SFGAO flags, see IShellFolder::GetAttributesOf.
psfgaoOut
[out] Pointer to a ULONG. On return, those attributes that are true for the object and were requested in sfgaoIn are set. An object's attribute flags can be zero or a combination of SFGAO flags. For a list of available SFGAO flags, see IShellFolder::GetAttributesOf.
Return Value
Returns S_OK if successful, or an error value otherwise.
我的调用过程是这个
procedure TForm1.Button1Click(Sender: TObject);
var
ir: integer;
wPath: WideString;
pbc: IBindCtx;
ppidl: PItemIDList;
sfgaoIn, psfgaoOut: Cardinal;
begin
wPath := Edit1.Text;
sfgaoin := 0;
new(ppidl);
pbc := nil;
ir := SHParseDisplayName(@wPath[1], pbc, ppidl, SFGAO_CANCOPY, psfgaoOut);
if S_OK = ir then
begin
if SHGetPathFromIDList(ppidl, @wPath[1]) then
Form1.Caption := wPath;
end;
dispose(ppidl);
end;
运行中,发现在ir := SHParseDisplayName(@wPath[1], pbc, ppidl, SFGAO_CANCOPY, psfgaoOut);这句总会出现Access error。
请问各位高人原因大概在什么地方,或者大家有没有使用范例?