I have a terrible problem, already struggeling for 2 weeks with it. So I decided to post on a forum. I searched the whole internet for answers. Asked my fellow students. Nobody knew the answer.
Oke, here it comes. In every .exe file there is a resource section which maintains the icons that are contained in the exe. There are often more than just one icon in every .exe stored. Every icon has an unique identifier. Now I try to get the identifier of the icon which is displayed as you see it normally when u view an .exe in your windows viewer for example.
I try to do it this way:
The trouble is with the ExtractAssociatedIcon. It should put the correct identifier in the variabele a_. It does not do this.Code:WORD a; WORD b; char arr = "C:\\monkey.exe"; LPWSTR wArr; buffer = (char*)malloc(10); memset(buffer, 0, 10); int buffSize = (int)strlen(arr) + 1; wArr = (wchar_t*)malloc(sizeof(wchar_t) * buffSize); MultiByteToWideChar(CP_ACP, 0, arr, buffSize, wArr, buffSize); if(ExtractAssociatedIcon(0, wArr, &a) == 0) // first 0 can be hInstance MessageBox(0, (LPCSTR)"fail",0,0); itoa(a, buffer, 10); MessageBox(0, (LPWSTR)buffert,0,0);
With resource hacker I can check if it returns me the right icon identifier. Guess what, it does not work for me. It worked once for me in the past. Don't know why it's not working now. I checked a lot of examples (Which are hard to find) and also the msdn (ExtractAssociatedIcon Function (Windows)) didn't help me further. Very rare problem I guess.
Thank god who can tell me what I'm doing wrong.