C/C++ Windows - ExtractIcon() not retrieving icon for all executables

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

#1

Here's just the snippet of what I'm doing:


Code:
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hProcessSnap == INVALID_HANDLE_VALUE)   return;

if(!Process32First( hProcessSnap, &pe32))
{
        CloseHandle(hProcessSnap); // clean the snapshot object
         return;
}    

do
{
     hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
     HICON icon = ExtractIcon((HINSTANCE)hProcess, pe32.szExeFile, 0);
}
while(Process32Next(hProcessSnap, &pe32));

Why does it work for some programs and not for others? It's basically only those, notepad, and the cmd prompt it gets icons for, no other programs.

Reply
#2

The [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms648068.aspx" rel="nofollow]

Code:
ExtractIcon()
[/url] function is designed to extract icons embedded in the executable/DLL as a resource (e.g. the icon is part of the
Code:
.exe
or
Code:
.dll
file). If the icon is dynamically loaded by the application (e.g. from a file using [url=http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045.aspx" rel="nofollow]
Code:
LoadImage()
[/url]) , then you can't retrieve it using
Code:
ExtractIcon()
.


That easily explains why you can't get the icon for Chrome tabs since they usually download the icon from a website and then display it. I would also suspect that any application that supports custom skinning is unlikely to allow you to extract its icon, or at best give you only the default icon.



To better understand the problem I suggest you visit this link:

Hidden Content
You must register or login to view this content.
Reply
 


Forum Jump:


Users browsing this thread: 1 Guest(s)

About Warrior Forum

Forum dedicated to Search Engine Optimization, Internet Marketing and Programming strategies for effective on-page and off-page SEO to make you rank #1 in the search engines.