开发者

VB.NET - Problems with SHQueryRecycleBin

I'm currently working on an application for my personal use. The idea is that you can open it up and reach all kind of stats of your computer (Recycle bin, Drives, Network and much more). Now I was working with the SHQueryRecycleBin from Win API.

Though I have some problems. And I've tried to look over outdated solutions for VB6 or VB.NET solutions that simply didn't work. I used the code reference from this source and to retrieve the size and count of files I used this source.

I put it in an timer, and after those 100 ticks (as I set it) were ran, I got this error:

File I/O of a structure with field 'cbSize' of type 'UInt32' is not valid.

The type of cbSize is UInteger which (apparently) automatic changes to an UInt32 - I think it's based on the system.

You should note that I'm on an Windows 7 x86 (64-bit). If have an solution for this or another piece of code that is easier than use Win API, let me 开发者_如何学编程know.

I have looked at the System.Management but wanted an bullet proof code that could interact with most systems.


I don't have vb.net handy to test, but the following code works perfectly well in vb6:

In a module:

Public Type SHRECYCLEBININFO
  cbSize As Long
  i64Size As Currency
  i64NumItems As Currency
End Type
Public Declare Function SHQueryRecycleBin Lib "shell32.dll" Alias "SHQueryRecycleBinA" (ByVal pszRootPath As String, pSHQueryRBInfo As SHRECYCLEBININFO) As Long

And in a form:

Private Sub Command1_Click()
    Dim info As SHRECYCLEBININFO
    Dim res As Long

    info.cbSize = Len(info)
    res = SHQueryRecycleBin("C:\", info)
    MsgBox "size: " & (info.i64Size * 10000) & " bytes" & vbCrLf & "items: " & (info.i64NumItems * 10000)
End Sub

Note the use of type "currency" - this is because vb6 doesn't have a normal data type for 64-bit integers. Type Currency is using 8 bytes, but keeps 4 decimal places, hence the multiplication by 10000 to get the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜