如何在VB.net中跨UNC路径使用shell32.dll ExtractAssociatedIcon

如何在VB.net中跨UNC路径使用shell32.dll ExtractAssociatedIcon,vb.net,dll,shell32.dll,Vb.net,Dll,Shell32.dll,我在C#中找到了很多示例,但无论我如何尝试,我都无法在VB中实现这一点。我可以提取的唯一图标是表示没有关联的文件的图标。如果有更好的方法,我也愿意接受。代码如下: 声明: Declare Auto Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As IntPtr, ByVal lpIconPat As String, ByRef lpiIcon As Int

我在C#中找到了很多示例,但无论我如何尝试,我都无法在VB中实现这一点。我可以提取的唯一图标是表示没有关联的文件的图标。如果有更好的方法,我也愿意接受。代码如下:

声明:

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

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 

提前谢谢

只需使用.NET Icon.ExtractAssociateDicon()方法。在没有bug的情况下执行完全相同的操作。@HansPassant我希望这是真的,但它声明这将抛出一个带有UNC路径的异常。我将声明中的第三个参数改为您建议的简短参数(在编辑您的评论之前),但这也不起作用。任何其他想法都非常感谢!