In Delphi 10.1.2 Berlin, I need to extract either the LARGE icon (32x32) or the SMALL icon (16x16) from an.EXE file, using a specific 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;
Using nil
for the excluded icon size creates a compiler error.
So how can I get the desired icon?
function ExtractIconEx(lpszFile: LPCWSTR; nIconIndex: Integer; var phiconLarge, phiconSmall: HICON; nIcons: UINT): UINT; stdcall;
, and clearlynil
can't be passed as avar
parameter. – Ken White