1
Dans Delphi 10.1.2 Berlin, je dois extraire soit l'icône LARGE (32x32) ou l'icône SMALL (16x16) à partir du fichier an.EXE, en utilisant un IconIndex spécifique:Get Small ou Large Icône de fichier Executable
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;
L'utilisation de nil
pour la taille d'icône exclue crée une erreur de compilation.
Alors, comment puis-je obtenir l'icône désirée?
https://stackoverflow.com/a/5955676/6426692 – Sami
qui fonctionne bien . – user1580348
La source (dans WinAPI.ShellAPI.pas) affiche la déclaration en tant que fonction ExtractIconEx (lpszFile: LPCWSTR; nIconIndex: Entier; var phiconLarge, phiconSmall: HICON; nIcons: UINT): UINT; stdcall; ', et clairement' nil' ne peut pas être passé en paramètre 'var'. –