Author: Christian Cristofori
There are a list of solution, but those are what i personally use for that work.
Answer:
You need to include the ShellAPI unit in your uses clausole!
1 2 // This returns how many icons are in a file.3 4 function DLLIconsCount(FileName: string): Integer;
5 var6 IconaGrande: HIcon;
7 IconaPiccola: HIcon;
8 begin9 Result := 0;
10 if (FileExists(FileName)) then11 begin12 Result := ExtractIconEx(PChar(FileName), -1, IconaGrande, IconaPiccola, 0);
13 end;
14 end;
15 16 // This returns if there're icons in a file17 18 function DLLHasIcons(FileName: string): Boolean;
19 begin20 Result := (DLLIconsCount(FileName) > 0);
21 end;
22 23 // This returns a TIcon for a given file and index.24 25 function GetDLLIcon(FileName: string; Index: Integer = 0): TIcon;
26 begin27 Result := TIcon.Create;
28 Result.Handle := 0;
29 if (DLLHasIcons(FileName)) then30 begin31 try32 if (Index < 0) then33 Index := 0;
34 if (Index > DLLIconsCount(FileName)) then35 Index := DLLIconsCount(FileName);
36 Result.Handle := ExtractIcon(0, PChar(FileName), Index);
37 finally38 end;
39 end;
40 end;
41 42 // This saves an icon from a DLL (EXE or ICO) to a ICO file.43 44 function ExportDLLIcon(OutputFile, InputFile: string; Index: Integer = 0): Boolean;
45 var46 Icona: TIcon;
47 begin48 Result := False;
49 Icona := GetDLLIcon(InputFile, Index);
50 if (not (Icona.Handle = 0)) then51 try52 Icona.SaveToFile(OutputFile);
53 finally54 if (FileExists(OutputFile)) then55 Result := True;
56 end;
57 Icona.Destroy;
58 end;
59 60 // This is like ExportDLLIcon, but it saves a bitmap file.61 62 function ExportDLLIconAsBitmap(OutputFile, InputFile: string; Index: Integer = 0):
63 Boolean;
64 var65 Icona: TIcon;
66 Immagine: TBitmap;
67 begin68 Result := False;
69 Icona := GetDLLIcon(InputFile, Index);
70 Immagine := TBitmap.Create;
71 if (not (Icona.Handle = 0)) then72 try73 Immagine.Assign(Icona);
74 Immagine.SaveToFile(OutputFile);
75 finally76 if (FileExists(OutputFile)) then77 Result := True;
78 end;
79 Icona.Destroy;
80 Immagine.Destroy;
81 end;