VB6中如何判断某个目录是回收站?
我正在尝试将代码移植到 这篇文章 到 VB6,但我遇到了崩溃。我很确定我的错误出在对 SHBindToParent
的调用中 (MSDN 条目),因为 SHParseDisplayName
返回 0 (S_OK
) 并且 ppidl
是正在设置。我承认我设置 riid 的机制(我使用了等效类型,UUID
)非常丑陋,但我认为更有可能我在 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您对 SHBindToParent 的调用正在崩溃,因为您需要传递 long,然后使用返回的指针将内存复制到您的类型中。当我在 google 上搜索 SHBindToParent 函数时,我发现了几篇文章,其中提到了操作系统支持,主要是 95 和 98。当我在 XP SP3 上尝试它时,我收到错误“不支持此类接口”。
以下是我修改代码以通过 GPF 的方法:
I believe your call to SHBindToParent is crashing because you need to pass longs, then use the returned pointers to copy the memory into your types. I found several posts when I googled the SHBindToParent function that mentioned OS support, mostly 95 and 98. When I tried it on XP SP3 I got an error "No such interface supported."
Here is how I modified your code to get past the GPF:
我为那些可能需要它的人提供了一个原型。
A prototype which I got to work, for those who may need it.