how to use shell32.dll ExtractAssociatedIcon across UNC path in VB.net

953 Views Asked by At

I have found plenty of examples in C#, but I cannot make this work in VB no matter what I try. The only icon I can extract is the one representing a file with no association. If there is a better approach I am open to that too. Here is the code:

Declaration:

Declare Auto Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As IntPtr, ByVal lpIconPat As String, ByRef lpiIcon As Integer) As IntPtr

Other Code:

Dim handle As IntPtr
Dim li As ListViewItem
Dim modul As System.Reflection.Module()

For Each filename As FileInfo In quotesFolder.GetFiles()

    If ImgLstQuotes.Images.ContainsKey(filename.Extension) Then
    Else
        modul = System.Reflection.Assembly.GetExecutingAssembly.GetModules()
        'handle = ExtractAssociatedIcon(Marshal.GetHINSTANCE(modul(0)), filename.FullName, -1) 'doesnt work

        'handle = ExtractAssociatedIcon(IntPtr.Zero(), filename.FullName, -1)  'doesn't work
        handle = ExtractAssociatedIcon(Process.GetCurrentProcess().Handle, filename.FullName, -1)  'doesn't work
        ImgLstQuotes.Images.Add(filename.Extension, Drawing.Icon.FromHandle(handle))
    End If

    li = LstVwQuotes.Items.Add(filename.Name, filename.Extension)
    li.Name = UCase(filename.Name)
    li.SubItems.Add(filename.LastWriteTime)

Next 

Thanks in advance!

0

There are 0 best solutions below