Recent

Author Topic: [Solved]How to programmatically determine if an external .exe has embedded icons  (Read 2442 times)

Ten_Mile_Hike

  • New Member
  • *
  • Posts: 40
Hi,
Simplest code to determine presence of embedded icon. NO NEED TO EXTRACT, just looking for presence

Thank You
« Last Edit: August 29, 2023, 11:25:55 pm by Ten_Mile_Hike »

Fibonacci

  • Sr. Member
  • ****
  • Posts: 319
  • Certified Internal Error Hunter
You are in luck, I happen to have such code :)

Code: Pascal  [Select][+][-]
  1. uses Windows;
  2.  
  3. function resenumtypes(hModule: HMODULE; lpType: LPSTR; lParam: LONG_PTR): BOOL; stdcall;
  4. begin
  5.   result := true;
  6.  
  7.   if lpType = RT_ICON then begin
  8.     PBoolean32(lParam)^ := true;
  9.  
  10.     result := false; //stop enumerating
  11.   end;
  12. end;
  13.  
  14. var
  15.   h: hwnd;
  16.   has_icon: boolean = false;
  17.  
  18. begin
  19.   h := LoadLibraryEx('C:\Windows\explorer.exe', 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE+LOAD_LIBRARY_AS_DATAFILE);
  20.  
  21.   if h > 0 then begin
  22.     EnumResourceTypes(h, @resenumtypes, LONG_PTR(@has_icon));
  23.  
  24.     writeln('has icon? ', has_icon);
  25.   end else begin
  26.     writeln('cant open file');
  27.   end;
  28.  
  29.   readln;
  30. end.

rvk

  • Hero Member
  • *****
  • Posts: 5920
You are in luck, I happen to have such code :)
I'm not sure if ANY icon is what is asked for or the actual program icon.
Your code looks for ANY icon (of I'm not mistaken)?

You can use ExtractIconEx for the actual program icon.
https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-extracticonexa

You can probably use the ExtractIcon function for this.

Fibonacci

  • Sr. Member
  • ****
  • Posts: 319
  • Certified Internal Error Hunter
He didn't specify it has to be MAINICON ;)

rvk

  • Hero Member
  • *****
  • Posts: 5920
He didn't specify it has to be MAINICON ;)
No (s)he didn't but seeing that only the presence is requested it would make sense it would be the MAINICON.

Anyway, now both methods are documented in this topic  ;)

Ten_Mile_Hike

  • New Member
  • *
  • Posts: 40
Thank You

 

TinyPortal © 2005-2018