1
私のコードで次のような問題があります。アイコンに渡されたWin32ハンドルが有効でないか、間違ったタイプです
SHFILEINFO宣言
Private Structure SHFILEINFO
Public hIcon As IntPtr ' : iconc
Public iIcon As Integer ' : icondex
Public dwAttributes As Integer ' : SFGAO_ flags
_
Public szDisplayName As String
_
Public szTypeName As String
End Structure
SHGetFileInfo宣言
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private Const MAX_PATH = 260
S:
Win32 handle that was passed to Icon is not valid or is the wrong type
コードの行は、以下のとおりでありますHGetFileInfo使用
Private Sub AddImageToImageListBox(ByVal strFileName As String)
On Error GoTo errHandler
Dim shInfo As SHFILEINFO
shInfo = New SHFILEINFO()
shInfo.szDisplayName = New String(vbNullChar, MAX_PATH)
shInfo.szTypeName = New String(vbNullChar, 80)
Dim hIcon As IntPtr
hIcon = SHGetFileInfo(strFileName, 0, shInfo, Marshal.SizeOf(shInfo), SHGFI_ICON Or SHGFI_SMALLICON)
Dim MyIcon As Drawing.Bitmap
MyIcon = Drawing.Icon.FromHandle(shInfo.hIcon).ToBitmap
imgAttachment.AddImage(MyIcon)
ilstAttachments.Items.Add(strFileName.ToString(), imgAttachment.Images.Count - 1)
Exit Sub
errHandler:
ErrMsg("AddImageToImageListBox (errHandler)")
End Sub
ランタイムここで
はSHGetFileInfoに渡される値です。記載された値は、上記SHGetFileInfoに渡される場合
strFileName = "Copy (223) of Uncollected Card - Multiple Pages.TIF"
shInfo.dwAttributes = 0
shInfo.hIcon = 0
shInfo.iIcon = 0
shInfo.szDisplayName = ""
shInfo.szTypeName = ""
エラー
、それは
MyIcon = Drawing.Icon.FromHandle(shInfo.hIcon).ToBitmap
達すると従ってHICON = 0
を作る0の値を返します次のエラーが発生しました
Win32 handle that was passed to Icon is not valid or is the wrong type
問題の原因を特定するのにお手伝いできますか?
は
私はあなたのコードを使用しようとしましたが、同じエラーがまだ現れました。 On Error GoToに関しては、カスタムMessageBoxを使ってエラーと位置を表示するので、Try/Catchメソッドを使用することはできません。 –
私のマシンで動作しました。 –
本当ですか?私はあなたのコードをコピーし、私の代わりに同じ問題が私のサイトで発生しました。ありがとうBTW。 –