VB6 中的 SHEmptyRecycleBin 不执行任何操作
我正在尝试清空回收站,作为释放硬盘空间的过程的一部分。他是我迄今为止得到的代码。在我的班级顶部:
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
然后在硬盘清理功能中:
SHEmptyRecycleBin(Empty, vbNullString, 0)
SHUpdateRecycleBinIcon
我也尝试了这个:
Dim lRetVal As Long
lRetVal = 0
lRetVal = SHEmptyRecycleBin(Empty, vbNullString, 0)
但它返回零,表明成功。有没有人以前使用过这个功能,或者知道为什么它不起作用?如果重要的话,此代码正在 ActiveX dll 中运行。
**编辑**
好吧,我想我之前一定是误读或误解了一些东西,因为我认为我看到的任何例子都给了我印象中最后一个变量使用 0 不会调用确认窗口。我尝试了这段代码:
Const SHERB_NOCONFIRMATION = &H1
Call SHEmptyRecycleBin(0, vbNullString, SHERB_NOCONFIRMATION)
...但它仍然不起作用。但是,如果我在调用 ActiveX dll 的 .exe 中使用此代码:
Const SHERB_NOCONFIRMATION = &H1
lRetVal = SHEmptyRecycleBin(Empty, vbNullString, SHERB_NOCONFIRMATION)
...它可以工作。我不明白为什么它在 .exe 中工作,而不是在 .dll 中工作,如果可能的话,我宁愿将所有代码保留在 .dll 中。
I'm trying to empty the recycle bin as part of a process that is freeing up hard disk space. He is the code I've got so far. At the top of my class:
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long
Private Declare Function SHUpdateRecycleBinIcon Lib "shell32.dll" () As Long
Then in the hard disk clean up function:
SHEmptyRecycleBin(Empty, vbNullString, 0)
SHUpdateRecycleBinIcon
I also tried this:
Dim lRetVal As Long
lRetVal = 0
lRetVal = SHEmptyRecycleBin(Empty, vbNullString, 0)
But it's returning a zero, indicating success. Has anyone ever used this function before, or have an ideas about why it wouldn't work? This code is being run from within an ActiveX dll, if that matters.
**EDIT**
Well, I think I must've misread or misunderstood something before, because I think whatever examples I looked at gave me the impression the confirmation window would not be called by using 0 for the last variable. I tried this code:
Const SHERB_NOCONFIRMATION = &H1
Call SHEmptyRecycleBin(0, vbNullString, SHERB_NOCONFIRMATION)
...and it still doesn't work. However, if I use this code in the .exe that is calling the ActiveX dll:
Const SHERB_NOCONFIRMATION = &H1
lRetVal = SHEmptyRecycleBin(Empty, vbNullString, SHERB_NOCONFIRMATION)
...it works. I can't figure out why it works in the .exe and not the .dll though, and I'd rather keep all the code in the .dll if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看此示例。
基本上
SHEmptyRecycleBin 0, vbNullString, 0
或Call SHEmptyRecycleBin(0, vbNullString, 0)
应该没问题,但它们传递的是实际的hwnd
用作所有者窗口的函数 UI。You can check this sample.
Basicly
SHEmptyRecycleBin 0, vbNullString, 0
orCall SHEmptyRecycleBin(0, vbNullString, 0)
should be ok, but they are passing an actualhwnd
for function UI to use as owner window.