我試圖將代碼this article移植到VB6,但我遇到崩潰。我很確定我的錯誤是在我撥打SHBindToParent
(MSDN entry)時發生的,因爲SHParseDisplayName
正在返回0(S_OK
),並且正在設置ppidl
。我承認我設置riid的機制(我使用了一個等效類型,一個UUID
)非常難看,但我認爲我更可能在psf
上做錯了什麼。如何判斷一個目錄是VB6中的回收站?
Private Declare Function SHParseDisplayName Lib "shell32" (ByVal pszName As Long, ByVal IBindCtx As Long, ByRef ppidl As ITEMIDLIST, sfgaoIn As Long, sfgaoOut As Long) As Long
Private Declare Function SHBindToParent Lib "shell32" (ByVal ppidl As Long, ByRef shellguid As UUID, ByVal psf As Long, ByVal ppidlLast As Long) As Long
Private Sub Main()
Dim hr As Long
Dim ppidl As ITEMIDLIST
Dim topo As String
Dim psf As IShellFolder
Dim pidlChild As ITEMIDLIST
topo = "c:\tmp\" '"//This VB comment is here to make SO's rendering look nicer.
Dim iid_shellfolder As UUID
iid_shellfolder.Data1 = 136422
iid_shellfolder.Data2 = 0
iid_shellfolder.Data3 = 0
iid_shellfolder.Data4(0) = 192
iid_shellfolder.Data4(7) = 70
hr = SHParseDisplayName(StrPtr(topo), 0, ppidl, 0, 0)
Debug.Print hr, Hex(hr)
hr = SHBindToParent(VarPtr(ppidl), iid_shellfolder, VarPtr(psf), VarPtr(pidlChild)) 'Crashes here
End Sub
(C++代碼這個標記是指在問題中引用) – Brian 2009-11-04 23:16:12