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:
int APIENTRY _tWinMain(HINSTANCE hInstance,
LPWORD a_ = (LPWORD)malloc(100);
LPWORD b_ = (LPWORD)malloc(100);
char arr = "C:\\test.exe";
*a_ = 0;
*b_ = 0;
buffert = (char*)malloc(10);
memset(buffert, 0, 10);
//mbstowcs(widearray, narrowarray, 100);
buffSize = (int)strlen(arr) + 1;
gah = (wchar_t*)malloc(sizeof(wchar_t) * buffSize);
MultiByteToWideChar(CP_ACP, 0, arr, buffSize, gah, buffSize);
if(ExtractAssociatedIconEx(0, (LPWSTR)gah, a_, b_) == NULL)
itoa(*a_, buffert, 10);
itoa(*b_, buffert, 10);
The trouble is with the ExtractAssociatedIcon. It should put the correct identifier in the variabele a_. It does not do this.
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 (http://msdn.microsoft.com/en-us/library/ms648067%28v=vs.85%29.aspx) didn't help me further. Very rare problem I guess.
Thank god who can tell me what I'm doing wrong.