Click here to Skip to main content
15,921,697 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionExtracting from DLLs Pin
MatrixCoder28-Feb-07 15:06
MatrixCoder28-Feb-07 15:06 
AnswerRe: Extracting from DLLs Pin
The ANZAC28-Feb-07 19:48
The ANZAC28-Feb-07 19:48 
GeneralRe: Extracting from DLLs Pin
MatrixCoder1-Mar-07 5:34
MatrixCoder1-Mar-07 5:34 
GeneralRe: Extracting from DLLs Pin
MatrixCoder1-Mar-07 16:54
MatrixCoder1-Mar-07 16:54 
GeneralRe: Extracting from DLLs Pin
The ANZAC1-Mar-07 19:00
The ANZAC1-Mar-07 19:00 
GeneralRe: Extracting from DLLs Pin
MatrixCoder2-Mar-07 3:26
MatrixCoder2-Mar-07 3:26 
GeneralMaybe Someone else can help. Pin
The ANZAC2-Mar-07 16:21
The ANZAC2-Mar-07 16:21 
GeneralRe: Extracting from DLLs [modified] Pin
TwoFaced2-Mar-07 19:23
TwoFaced2-Mar-07 19:23 
I've tried that code before and your right it does save them at a low quality. However, the extraction works just fine and as far as I know it's the only way to get at the icons. You don't actually need to save the icons to view them however. Once the icon has been extracted you can add it to your imagelist and then add a new item to the listview. What I would do is use the code from that example as a base and modify it to suit your needs. I created this example using the 'relevent' code from that project and tweaked it slightly. The end result is a method you can call to popullate a listview with the icons from a given file. Feel free to use it or modify it to suite your needs. I did it quickly so who knows what I missed but it worked great when I tested it. All you need to do is pass to the function the file you want to read and the listview to use for display.
Imports System.IO
Public Class ExtractIcon
    Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
            (ByVal lpszFile As String, _
             ByVal nIconIndex As Integer, _
             ByRef phiconLarge As Integer, _
             ByRef phiconSmall As Integer, _
             ByVal nIcons As Integer) As Integer
    Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Integer) As Integer
    Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As Integer) As Integer

    'calls API to determine how many icons are embedded in the file
    Private Shared Function GetNumberOfIcons(ByVal fl As String) As Integer
        Return ExtractIconEx(fl, -1, 0, 0, 0)
    End Function

    'Extracts each icon from the file given, and saves it to the destination directory
    Public Shared Sub ExtractIconsFromFile(ByVal file As String, ByVal list As ListView)
        Dim info As New IO.FileInfo(file)
        Dim numicons As Integer  ' number of regular icons in the file
        Dim retval As Integer  ' return value
        Dim hInstance As IntPtr = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0))


        'Make sure we have an image list for our listview
        If list.LargeImageList Is Nothing Then
            Dim iconImageList As New ImageList
            iconImageList.ImageSize = New Size(32, 32)
            iconImageList.ColorDepth = ColorDepth.Depth32Bit
            list.LargeImageList = iconImageList
        End If

        list.Items.Clear()
        numicons = GetNumberOfIcons(info.FullName)
        For i As Integer = 0 To numicons - 1
            retval = ExtractIcon(hInstance, info.FullName, i)
            If retval > 0 Then
                Dim ico As Icon = Icon.FromHandle(New IntPtr(retval))
                list.LargeImageList.Images.Add(retval.ToString, ico)
                list.Items.Add(retval.ToString, retval.ToString)
            End If
            DestroyIcon(retval)
        Next
    End Sub
End Class



-- modified at 1:31 Saturday 3rd March, 2007
GeneralRe: Extracting from DLLs Pin
MatrixCoder3-Mar-07 5:42
MatrixCoder3-Mar-07 5:42 
QuestionSmall Project - Looking For Community Input Pin
Ian Woods28-Feb-07 14:45
Ian Woods28-Feb-07 14:45 
QuestionPLEASE HELP :( Pin
İsmail Durmaz28-Feb-07 10:42
İsmail Durmaz28-Feb-07 10:42 
QuestionVb Forms and Crystal Reports Pin
China-Gary28-Feb-07 9:45
China-Gary28-Feb-07 9:45 
QuestionVB6.0 -> VB.NET conversion (A question about COM references) Pin
BRShroyer28-Feb-07 8:45
BRShroyer28-Feb-07 8:45 
AnswerRe: VB6.0 -> VB.NET conversion (A question about COM references) Pin
Christian Graus28-Feb-07 10:04
protectorChristian Graus28-Feb-07 10:04 
QuestionReading Excel Data with VB.NET 2005 Pin
Jawa200628-Feb-07 8:41
Jawa200628-Feb-07 8:41 
Questionhow can we add winsock control in our vb.net application Pin
onrivman28-Feb-07 5:53
onrivman28-Feb-07 5:53 
AnswerRe: how can we add winsock control in our vb.net application Pin
Tim Carmichael28-Feb-07 8:05
Tim Carmichael28-Feb-07 8:05 
QuestionColor DataGridView cell on exception Pin
penguin500028-Feb-07 5:06
penguin500028-Feb-07 5:06 
Newsselectin in combobox........ Pin
manni_n28-Feb-07 2:43
manni_n28-Feb-07 2:43 
GeneralRe: selectin in combobox........ Pin
CPallini28-Feb-07 4:42
mveCPallini28-Feb-07 4:42 
QuestionRe: selectin in combobox........ Pin
manni_n28-Feb-07 6:35
manni_n28-Feb-07 6:35 
AnswerRe: selectin in combobox........ Pin
CPallini28-Feb-07 9:02
mveCPallini28-Feb-07 9:02 
QuestionCrystal reports Problem in vb.net2005 Pin
amaneet28-Feb-07 2:35
amaneet28-Feb-07 2:35 
Questionapplication.Run Pin
amaneet28-Feb-07 2:19
amaneet28-Feb-07 2:19 
AnswerRe: application.Run Pin
Colin Angus Mackay28-Feb-07 4:07
Colin Angus Mackay28-Feb-07 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.