C/C++ Windows API

Moderators: Lundin
Number of threads: 443
Number of posts: 1215

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
[Win32 ExtractAssociatedIconEx] Try to get main icon identifier Posted by links4all on 28 Apr 2011 at 2:21 PM
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:
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);


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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.