Solved

Need help using ExtractIcon API.

Posted on 1998-04-25
9
183 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

803 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