掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
フォルダの参照ダイアログ (ID:142762)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
環境 XP VB.net 2002 Standard フォルダの参照ダイアログを表示してパスを取得するクラスを作りたいのですが、下記の最後の方の、Call SHGetPathFromIDList(lReturn, stPath)で、エラーが出てしまいます。内容は、「System.NullReferenceException' のハンドルされていない例外が ShkTD.exe で発生しました。 追加情報 : オブジェクト参照がオブジェクト インスタンスに設定されていません。」と出ます。 お忙しいところ恐れ入りますが、宜しくお願いします。 Private Declare Function SHBrowseForFolder Lib "SHELL32.DLL" Alias "SHBrowseForFolderA" ( _ ByRef lpBrowseInfo As TypeBrowseInfo _ ) As Long Private Declare Function SHGetPathFromIDList Lib "SHELL32.DLL" Alias "SHGetPathFromIDListA" ( _ ByVal pidl As Long, _ ByVal pszPath As String _ ) As Long Private Declare Sub CoTaskMemFree Lib "OLE32.DLL" (ByVal pv As Long) Private Structure TypeBrowseInfo Dim OwnerHandle As Long Dim Root As Long Dim DisplayName As String Dim Description As String Dim Flags As BifOptions Dim lpfn As Long Dim lParam As String Dim iImage As Long End Structure 'Type Private Enum BifOptions ReturnOnlyFileSystemDirectories = &H1 HideNetworkResource = &H2 StatusText = &H4 OnlyNetworkResource = &H8 ShowEditBox = &H10 Validate = &H20 NewDialogStyle = &H40 BrowseForComputer = &H1000 BrowseForPrinter = &H2000 BrowseIncludeFiles = &H4000 End Enum ' プロパティ 変数 Private m_SelectedPath As String Private Browseinfo As TypeBrowseInfo Dim bi As TypeBrowseInfo Public Property SelectedPath() As String Get Return m_SelectedPath End Get Set(ByVal Value As String) m_SelectedPath = Value End Set End Property Public Property Description() As String Get Return Browseinfo.Description End Get Set(ByVal Value As String) Browseinfo.Description = Value End Set End Property Public Property ShowNewFolderButton() As Boolean Get Return ((Browseinfo.Flags And BifOptions.NewDialogStyle) > 0) End Get Set(ByVal Value As Boolean) If ShowNewFolderButton = True Then Browseinfo.Flags = Browseinfo.Flags Or BifOptions.NewDialogStyle Else Browseinfo.Flags = Browseinfo.Flags And Not BifOptions.NewDialogStyle End If End Set End Property Public Sub New() Browseinfo.Flags = Browseinfo.Flags Or BifOptions.NewDialogStyle 'NewDialogStyle End Sub '「フォルダの参照」ダイアログを表示する Public Function ShowDialog(Optional ByVal hOwnerHandle As Long = 0&) As Boolean Dim lReturn As Long Dim stPath As String ' 親ハンドルを設定する Browseinfo.OwnerHandle = hOwnerHandle 'Browseinfo.DisplayName = New String(vbNullChar, MAX_PATH) 'Browseinfo.Flags = BifOptions.ReturnOnlyFileSystemDirectories '「フォルダの参照」ダイアログを呼び出す lReturn = SHBrowseForFolder(bi) ' OK が押下された場合 If lReturn <> 0 Then stPath = Microsoft.VisualBasic.Strings.StrDup(65536, Microsoft.VisualBasic.vbNullChar) Call SHGetPathFromIDList(lReturn, stPath) Call CoTaskMemFree(lReturn) Me.SelectedPath = Microsoft.VisualBasic.Strings.Left _ (stPath, Microsoft.VisualBasic.Strings.InStr(stPath, Microsoft.VisualBasic.vbNullChar) - 1) ShowDialog = True End If End Function
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.