use*_*591 5 delphi winapi windows-shell
我试图在Delphi中获取pidl形式的路径时获得访问冲突,并且返回的pidl为nil.这是我的代码:
type
// TParseDisplayName = function(pszPath: PChar; pbc: pointer; var pidl: PItemIDList; sfgaoIn: LongWord; var psfgaoOut: LongWord): LongInt;
TParseDisplayName = function(pszPath: PWideChar; pbc: IBindCtx; var pidl: PItemIDList; sfgaoIn: ULong; var psfgaoOut: ULong): HResult;
var
SHParseDisplayName: TParseDisplayName;
SHELL32DLLHandle : THandle;
procedure test();
var
ws : WideString;
tmpLongWord: ULong;
lpItemID: PItemIDList;
begin
//ws := 'Mes documents';
CoInitialize(nil);
// path to test
ws := 'C:\inetsdk\Nouveau Document WordPad.doc';
if (SHParseDisplayName(PWideChar(ws), nil, lpItemID, 0, tmpLongWord) = S_OK) then
if not assigned(lpItemID) then
s := SysErrorMessage(getLastError);
CoUnInitialize();
end;
initialization
SHELL32DLLHandle := LoadLibraryW('shell32.dll');
@SHParseDisplayName := GetProcAddress(SHELL32DLLHandle, 'SHParseDisplayName');
Run Code Online (Sandbox Code Playgroud)
声明TParseDisplayName省略了调用约定.你需要包括stdcall.
TParseDisplayName = function(pszPath: PWideChar; pbc: IBindCtx;
var pidl: PItemIDList; sfgaoIn: ULong; var psfgaoOut: ULong): HResult; stdcall;
Run Code Online (Sandbox Code Playgroud)
如果未指定调用约定,则使用默认调用约定.默认的调用约定是register.这对于参数传递和清理具有不同的语义,这导致您遇到的运行时错误类型.几乎所有使用的Windows API函数stdcall.
| 归档时间: |
|
| 查看次数: |
575 次 |
| 最近记录: |