1
在Delphi 10.1.2柏林,我需要提取無論是大圖標(32×32)或從an.EXE文件中的小圖標(16×16),使用特定的IconIndex:獲得小或大圖標在可執行文件
function GetIconFromExecutableFile(const AFileName: string; const Large: Boolean; const AIconIndex: Integer): TIcon;
var
Icon: HICON;
ExtractedIconCount: UINT;
ThisIconIdx: Integer;
F: string;
begin
Result := nil;
try
ThisIconIdx := AIconIndex;
F := AFileName;
if Large then
begin
// error on nil: [dcc32 Error]: E2033 Types of actual and formal var parameters must be identical
ExtractedIconCount := ExtractIconEx(PChar(F), ThisIconIdx, Icon, nil, 1);
end
else
begin
// error on nil: [dcc32 Error]: E2033 Types of actual and formal var parameters must be identical
ExtractedIconCount := ExtractIconEx(PChar(F), ThisIconIdx, nil, Icon, 1);
end;
Win32Check(ExtractedIconCount = 1);
Result := TIcon.Create;
Result.Handle := Icon;
except
Result.Free;
raise;
end;
end;
對排除的圖標大小使用nil
會產生編譯器錯誤。
那麼我怎樣才能得到所需的圖標?
https://stackoverflow.com/a/5955676/6426692 – Sami
行之有效。 – user1580348
源代碼(在WinAPI.ShellAPI.pas中)顯示聲明爲'function ExtractIconEx(lpszFile:LPCWSTR; nIconIndex:Integer; var phiconLarge,phiconSmall:HICON; nIcons:UINT):UINT; stdcall;',顯然'nil'不能作爲'var'參數傳遞。 –