Hallo,
ich benutze die Funktion SHGetFileInfo um Icons auszulesen.
Normalerweise gebe ich einen UNC-Pfad ein. Wenn kein Netzwerk vorhanden ist,
nutze ich einen lokalen Pfad! Allerdings fliegt die Funktion bei mir komischerweise
ohne Netzwerk mit lokalem Pfad an einigen Rechnern raus. Leider kann ich nicht genau
bestimmen was der unterschied ist!
Imports System.Runtime.InteropServices
<Serializable()> _
Public Class IconLader
<StructLayout(LayoutKind.Sequential)> _
Public Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As IntPtr
Public dwAttributes As UInteger
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Class Win32
Public Const SHGFI_ICON As UInteger = &H100
Public Const SHGFI_LARGEICON As UInteger = &H0 'Large icon
Public Const SHGFI_SMALLICON As UInteger = &H1 'Small icon
<DllImport("shell32.dll")> _
Public Shared Function SHGetFileInfo(ByVal pszPath As String, ByVal _
dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, ByVal _
cbSizeFileInfo As UInteger, ByVal uFlags As UInteger) As IntPtr
End Function
End Class
Public Function ladeIcon32(ByVal Dateiname As String) As Drawing.Icon
Dim shinfo As New SHFILEINFO()
Dim hImgSmall As IntPtr = Win32.SHGetFileInfo(Dateiname, 0, shinfo, CUInt( _
Marshal.SizeOf(shinfo)), Win32.SHGFI_ICON Or Win32.SHGFI_LARGEICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)
End Function
Public Function ladeIcon16(ByVal Dateiname As String) As Drawing.Icon
Dim shinfo As New SHFILEINFO()
Dim hImgSmall As IntPtr = Win32.SHGetFileInfo(Dateiname, 0, shinfo, CUInt( _
Marshal.SizeOf(shinfo)), Win32.SHGFI_ICON Or Win32.SHGFI_SMALLICON)
Return System.Drawing.Icon.FromHandle(shinfo.hIcon)
End Function
End Class Fehlermeldung:
System.ArgumentException: Der an Icon übergebene Win32-Handle ist ungültig oder _
hat den falschen Typ.
bei System.Drawing.Icon..ctor(IntPtr handle, Boolean takeOwnership)
bei System.Drawing.Icon..ctor(IntPtr handle)
bei System.Drawing.Icon.FromHandle(IntPtr handle)
bei Klassen.IconLader.ladeIcon16(String Dateiname) in _
D:\Entwicklung\Software\Produkt.Interface\IconLader.vb:Zeile 39.
bei Produkt.UserInterfaces.ctrlExplorer.DokImage(DokExDokument d) in _
D:\Entwicklung\Software\Produkt.Interface\Auftrag\Dokument _
Explorer\Controls\ctrlExplorer.vb:Zeile 313. Sprache: VB.NET 4.0
Entwicklungsumgebung: VS 2010
Betriebssystem: Windows 7
|