VB6 中的 SHEmptyRecycleBin 不执行任何操作

发布于 2024-10-10 17:30:16 字数 1175 浏览 4 评论 0原文

我正在尝试清空回收站,作为释放硬盘空间的过程的一部分。他是我迄今为止得到的代码。在我的班级顶部:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2024-10-17 17:30:17

您可以查看此示例

基本上 SHEmptyRecycleBin 0, vbNullString, 0Call SHEmptyRecycleBin(0, vbNullString, 0) 应该没问题,但它们传递的是实际的 hwnd用作所有者窗口的函数 UI。

You can check this sample.

Basicly SHEmptyRecycleBin 0, vbNullString, 0 or Call SHEmptyRecycleBin(0, vbNullString, 0) should be ok, but they are passing an actual hwnd for function UI to use as owner window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文