Solved

Need help using ExtractIcon API.

Posted on 1998-04-25
9
179 Views
Last Modified: 2013-12-03
I am writting an applications that extracts the icon from a file. When I
open a file and use the name to extract the icon with the icon index= -1, so
I can get the total number of icons in the file, the return value is NULL.
The following is the code I am using:

   pWin->hInst ==== The global instance
   pWin->szFile === The path and name of the file, which is taken from the
opendlg.

   // Get number of icons in file
   lstIcons = ExtractIcon(pWin->hInst, pWin->szFile, -1);

  // Display messagebox if there are no icons in file
     if (lstIcons==NULL)
         MessageBox(hwnd,"File doesn't have an icon",
                                 "No Icon", MB_ICONINFORMATION);

Does anyone know if I am doing something wrong. I am using straight C, no
MFC or OWL.

Eliud
0
Comment
Question by:justin_robledo
  • 5
  • 4
9 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1397208
Check the hInst variable.  Where do you assign it.
Check the szFile variavle.  Are you supplying the full pathname?
Check the cause of the error using the GetLastError() function.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1397209
So, what was the culprit?
0
 

Author Comment

by:justin_robledo
ID: 1397210
Your suggestion worked to a certain point. I declared the global instance after creating the main window and passed the file name without parsing out the path. Now I can only extract the icons in my own program. When I try opening any other program, I still get a NULL value. Can you help me some more.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1397211
What does GetLastError() say?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:justin_robledo
ID: 1397212
I don't know if this is right but this is the code that I used to get the error code:
            DWORD e;
            e=GetLastError();
            SetDlgItemInt(pWin->hdlg,IDC_E1, e, FALSE);
And the value is 32.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1397213
Are you using GetLastError() IMMEDIATELY after the call that fails?
Error 32 is SHARING_VIOLATION.  How do you open the file?  What is the sharing mode?  What is the access (read/write)?
0
 

Author Comment

by:justin_robledo
ID: 1397214
I initialize an open dialog box with the following code,
        // Initialize OPENFILENAME
      pWin->ofn.lStructSize = sizeof(OPENFILENAME);
      pWin->ofn.hwndOwner = hwnd;
      pWin->ofn.lpstrFile = pWin->szFile;
      pWin->ofn.nMaxFile = sizeof(pWin->szFile);
      pWin->ofn.lpstrFilter = "Executable Files\0*.EXE\0Dll Files\0*.DLL\0Icon Files\0*.ICO\0All Files\0*.*\0";
      pWin->ofn.nFilterIndex = 1;
      pWin->ofn.lpstrFileTitle = NULL;
      pWin->ofn.nMaxFileTitle = 0;
   pWin->ofn.lpstrTitle = NULL;
      pWin->ofn.lpstrInitialDir = NULL;
      pWin->ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

then I call GetOpenFileName(&pWin->ofn). I then pass pWin->szFile to the ExtractIcon API function and then call GetLastError().
0
 
LVL 11

Expert Comment

by:alexo
ID: 1397215
Try using the OFN_SHAREAWARE flag.
0
 

Author Comment

by:justin_robledo
ID: 1397216
I found the problem. It was that I was opening the file when all I needed is just the path and file name. I did not have to open the file to use the ExtractIcon API function. I did not figure that opening the file would give me an error. Thanks for all your help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now