?
Solved

Need help using ExtractIcon API.

Posted on 1998-04-25
9
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 200 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 11

Expert Comment

by:alexo
ID: 1397211
What does GetLastError() say?
0
 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

764 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