Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[Win32 ExtractAssociatedIconEx] Try to get main icon identifier

Hi folks,

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:
[code]int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{

LPWORD a_ = (LPWORD)malloc(100);
LPWORD b_ = (LPWORD)malloc(100);
char* buffert;
char arr[] = "C:\test.exe";
int buffSize;
LPWSTR gah;

*a_ = 0;
*b_ = 0;
buffert = (char*)malloc(10);
memset(buffert, 0, 10);

//wchar_t widearray[100];
//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);
MessageBox(0,(LPCWSTR)gah,0,0);
if(ExtractAssociatedIconEx(0, (LPWSTR)gah, a_, b_) == NULL)
MessageBox(0, _T("fail"),0,0);


itoa(*a_, buffert, 10);
MessageBox(0, (LPWSTR)buffert,0,0);
itoa(*b_, buffert, 10);
MessageBox(0, (LPWSTR)gah,0,0);[/code]

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(v=vs.85).aspx) didn't help me further. Very rare problem I guess.
Thank god who can tell me what I'm doing wrong.
Sign In or Register to comment.