gpt4 book ai didi

c++ - 我怎么知道一个目录是VB6中的回收站?

转载 作者:行者123 更新时间:2023-11-30 04:40:11 31 4
gpt4 key购买 nike

我正在尝试移植 this article 中的代码到 VB6,但我遇到了崩溃。我很确定我的错误是在调用 SHBindToParent ( MSDN entry ) 时,因为 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

最佳答案

我相信您对 SHBindToParent 的调用会崩溃,因为您需要传递长整数,然后使用返回的指针将内存复制到您的类型中。当我用谷歌搜索提到操作系统支持的 SHBindToParent 函数时,我发现了几篇帖子,主要是 95 和 98。当我在 XP SP3 上尝试它时,我得到一个错误“不支持这样的接口(interface)。”

以下是我如何修改您的代码以通过 GPF:

Option Explicit

Private Declare Function SHParseDisplayName Lib "shell32" (ByVal pszName As Long, ByVal IBindCtx As Long, ByRef ppidl As Long, ByVal sfgaoIn As Long, ByRef sfgaoOut As Long) As Long
Private Declare Function SHBindToParent Lib "shell32" (ByVal ppidl As Any, ByRef shellguid As UUID, ByRef psf As Any, ByRef ppidlLast As Any) As Long

Private Type SHITEMID
cb As Long
abID As Byte
End Type

Private Type ITEMIDLIST
mkid As SHITEMID
End Type

Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type


Private Sub Command1_Click()
Dim hr As Long
Dim ppidl As Long
Dim topo As String
Dim psf As IShellFolder
Dim pidlChild As Long
Dim iid_shellfolder As UUID
Dim lpIDList2 As Long

topo = "C:\Temp"

' create a uuid = {B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}'
iid_shellfolder.Data1 = &HB7534046
iid_shellfolder.Data2 = &H3ECB
iid_shellfolder.Data3 = &H4C18
iid_shellfolder.Data4(0) = 190
iid_shellfolder.Data4(1) = 78
iid_shellfolder.Data4(2) = 100
iid_shellfolder.Data4(3) = 205
iid_shellfolder.Data4(4) = 76
iid_shellfolder.Data4(5) = 183
iid_shellfolder.Data4(6) = 214
iid_shellfolder.Data4(7) = 172

hr = SHParseDisplayName(StrPtr(topo), ByVal 0&, lpIDList2, ByVal 0&, ByVal 0&)
' Debug.Print hr, Hex(hr)'
hr = SHBindToParent(lpIDList2, iid_shellfolder, psf, pidlChild) 'retuns "No such interface supported" error

End Sub

关于c++ - 我怎么知道一个目录是VB6中的回收站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1677345/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com