API函數 並未將物件參考設定為物件的執行個體 (急)
我在調用API函數SHELL32時運行到紅色部份提示錯誤"並未將物件參考設定為物件的執行個體",請問是什麼原因?
我的代碼如下:
Imports System.Text
Imports System.Runtime.InteropServices
Imports Shell32
Public Class SetStorePath
Inherits System.Windows.Forms.Form
Dim selectID As String
Public Structure browseinfo
Public howner As Long
Public pidlroot As Long
Public pszdisplayname As String
Public lpsztitle As String
Public ulflags As Long
Public lpfn As Long
Public lparam As Long
Public iImage As Long
End Structure
Public Const bif_returnonlyfsdirs = &H1
Public pidl As Long
Public Declare Function SHGetPathFormIDList Lib "shell32.dll" Alias "SHGetPathFormIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (ByVal lpBrowseinfo As browseinfo) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bi As browseinfo
Dim r As Long
Dim pidl As Long
Dim path As String
Dim pos As Integer
bi.howner = Me.Handle.GetHashCode
bi.pidlroot = 0&
bi.lpsztitle = "選擇文件夾"
bi.ulflags = bif_returnonlyfsdirs
pidl = SHBrowseForFolder(bi)
path = Space$(512)
r = SHGetPathFormIDList(pidl, path)
If r Then
pos = InStr(path, Chr(0))
Me.TextBox1.Text = path.Substring(path, pos - 1)
Else
Me.TextBox1.Text = ""
End If
End Sub
End Class