[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Need help using ExtractIcon API.

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
justin_robledo
Asked:
justin_robledo
  • 5
  • 4
1 Solution
 
alexoCommented:
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
 
alexoCommented:
So, what was the culprit?
0
 
justin_robledoAuthor Commented:
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
alexoCommented:
What does GetLastError() say?
0
 
justin_robledoAuthor Commented:
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
 
alexoCommented:
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
 
justin_robledoAuthor Commented:
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
 
alexoCommented:
Try using the OFN_SHAREAWARE flag.
0
 
justin_robledoAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now