dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] Extracting Icons bigger than 32bpp from a DLL or EXE.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    470

    Resolved [RESOLVED] Extracting Icons bigger than 32bpp from a DLL or EXE.

    I am using extractIconEx and DrawIconEx to extract any embedded icons in a supplied DLL or EXE. I'd like to display the extracted image as 128 or 256bpp but it seems that the process I have selected only handles icons up to 32x32.

    ' icon count
    lIcons = ExtractIconEx(sExeName, -1, 0, 0, 0)

    ' get the handle
    Call ExtractIconEx(sExeName, lIndex, glLargeIcons(lIndex), glSmallIcons(lIndex), 1)

    ' draw the image
    Set .Picture = LoadPicture("")
    .AutoRedraw = True

    Call DrawIconEx(.hDC, 0, 0, glLargeIcons(lIndex), IconSize, IconSize, 0, 0, DI_NORMAL)
    .Refresh
    End With

    I want to keep it simple if possible, is there another API function that I can use to extract or draw the larger size of icon?

    I briefly tried SHGetFileInfo but that seems limited to 32 x 32 as well.

    I only want to extract from a DLL or EXE.

    Any thoughts?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,597

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    Quote Originally Posted by yereverluvinuncleber View Post
    I want to keep it simple if possible, is there another API function that I can use to extract or draw the larger size of icon?

    I briefly tried SHGetFileInfo but that seems limited to 32 x 32 as well.

    I only want to extract from a DLL or EXE.

    Any thoughts?
    You can draw an icon any size you want, scaling won't be great when drawing larger than actual size. You simply supply the cx & cy parameters in DrawIconEx.

    Retrieving icons for most APIs is usually limited to system settings for small (16x16) and large (32x32) scaled to system DPI when app is DPI-aware. For larger icons, extra large (48x48) and jumbo (256x256), there is a way to get them, but not necessarily as simple.
    http://www.vbforums.com/showthread.p...ge-list-to-VB6

    To retrieve actual size icons, whatever sizes are available, this gets more complex. You will want to scan the executable/dll resources, retrieving the icons and sizes that exist inside of it. Then choose the one you want to extract. In this scenario, you will be using several resource-related APIs and enumerations.

    Now you have a bit more information to think about, how do you want to move forward?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    470

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    Thankyou for your very quick response.

    Of course, I knew it would be complex!

    I was hoping there was another API function that would simply do the job.

    My basic is not up to scanning the binary and identifying the embedded icons, extracting the correct icon and displaying it. I have the code to extract a 32x32 icon and it works and I may just leave a message on the larger image saying "this function is currently unsupported" and just display the small icon format.

    I hadn't realised the complexity in handling all the different image methods and my mind is now rather over-loaded.

    Your code to read the various formats of data is very impressive and if I had the brain and the time I would disassemble your code and try to understand it. At the moment though I can make neither head nor tail of it, it is so comprehensive and voluminous, I don't really know where to start.

    All I want is a function that looks not so different from the the original drawIconEx and for it to handle the larger icon size. Hmmmmm.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,597

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    Quote Originally Posted by yereverluvinuncleber View Post
    Thankyou for your very quick response.

    Of course, I knew it would be complex!

    I was hoping there was another API function that would simply do the job.

    All I want is a function that looks not so different from the the original drawIconEx and for it to handle the larger icon size. Hmmmmm.
    Did you look at post #4 in that link I provided? Not much code at all, except for the API declarations.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    470

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    Yes, yes, fascinating and I'm looking at it and I see it refers to some sort of referenced image list but it is unclear to me how to get the input from a defined DLL or EXE, say from a commonDialogBox.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,597

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    Quote Originally Posted by yereverluvinuncleber View Post
    Yes, yes, fascinating and I'm looking at it and I see it refers to some sort of referenced image list but it is unclear to me how to get the input from a defined DLL or EXE, say from a commonDialogBox.
    That function needs an imagelist item index which you can get with SHGetFileInfo. But SHGetFileInfo isn't going to get you all the icons in an exe/dll. There is another API that you can potentially use, though I personally have never used: SHDefExtractIcon. That API allows you to use indexes just as you would with ExtractIconEx. The idea here is to get the count from ExtractIconEx, then loop thru them and get the icon from SHDefExtractIcon.

    Some notes about that API which may not be what you want to hear. I don't know if it is possible to receive just one icon or whether it will give you both small & large. The good news is that you can specify the size. The bad news from what I've read is that the icon is scaled if the requested size is not found. You'll have to play with the API to see if it does what you want. It is very similar in use to ExtractIconEx

    I think the only way to actually know what sizes each icon is within the exe/dll is to enumerate them via the resource-related APIs, i.e., FindResourceEx and others. If you can enumerate them, you can extract them and draw them.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    470

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    I'll try it, thanks for the tip

  8. #8
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,504

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    You can use this API instead which let's you extract bigger icons. Seems like a hidden API, not documented much.

    Code:
    Private Declare Function PrivateExtractIcons Lib "user32" Alias "PrivateExtractIconsW" (ByVal sFile As Long, ByVal nIconIndex As Long, ByVal cxIcon As Long, ByVal cyIcon As Long, phIcon As Long, pIconID As Long, ByVal nIcons As Long, ByVal lFlags As Long) As Long
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    470

    Re: Extracting Icons bigger than 32bpp from a DLL or EXE.

    I did use that undocumented API in the end, having tried several other methods.

    You can see it here in action on the last post in this thread:
    http://www.vbforums.com/showthread.p...gs-Enhancement

    I eventually found some documentation on the undocumented API PrivateExtractIcons on the interweb... Unsure where to place this at the moment so I will just drop it here:

    PrivateExtractIcons

    This function extracts the ICON of a resource ID, that is, extracts the entire .ICO file from the exe or dll. For example, a toolbar icon icon, if it happens to be the first one, then its return phicon will be the ico icon resource is a whole

    Name
    PrivateExtractIcons ICON with a resource ID

    parameters

    lpszFile[at]
    Type: lpctstr
    The file's path and name are extracted from the icon(s).

    nIconIndex[at]
    Type: int
    The zero-based index extracted by the first icon. For example, if the value is zero, the function extracts the first icon in the specified file.

    cxIcon[at]
    Type: int
    Horizontal icon size. Look at the comments.

    cyIcon[at]
    Type: int
    Vertical icon size. Look at the comments.

    Phicon (, optional)
    Type: HICON *
    The handle of the returned pointer array icon.

    Piconid(, optional)
    Type: Use UINT *
    The icon for the pointer to return the resource identifier is best for the current display device. The return identifier is 0xffffffff if the identifier for this format is not available. The return identifier identifier cannot be 0, otherwise.

    nIcons[at]
    Type: use uint
    The icon extracts the number from the file. This parameter is the only valid extraction. Exe and. DLL file.

    Sign (at)
    Type: use uint
    Controls the flag specified by this function. These flags LR_* use the banner loadImage feature.

    Return Value

    Type: use uint
    If the phicon parameter is empty, the function succeeds and the return value is the number of files in the icon. If the function fails, the return value is 0.

    If the phicon parameter is not NULL and the function succeeds, the return value is the number of icon extracts. Otherwise, the return value is 0 xffffffff if the file is not found.

    Description

    From the executable (.exe), this function extracts DLL (.DLL), icon (ico), cursor (.cur), animated cursor (about ani) and bitmap (bmp format) files. Extraction from embedded Windows 3. x 16-bit executables (.exe or .dll) are also supported.

    The cxIcon and cyIcon parameters specify the size of the extracted icon. Two sizes can be obtained by extracting the LOWORD HIWORD and the second size of the parameter from the first size. For example, the MAKELONG (24, 48) cxIcon and cyIcon parameters will extract 24 and 48 icon sizes.

    You must destroy all icons after the call to extract the PrivateExtractIcons using the DestroyIcon function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width