I am attempting to port the code in this article to VB6, but I'm experiencing crashing. I'm pretty sure my error is in my call to SHBindToParent
(MSDN entry) since SHParseDisplayName
is returning 0 (S_OK
) and ppidl
is being set. I admit my mechanism of setting the riid (I used an equivalent type, a UUID
) is pretty ugly, but I think it more likely I'm doing something wrong with psf
.
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