这边有个获取回收站大小和文件个数的函数,但是目前只在32位目标平台才能用,请问如何更改让其在64位平台也能够使用???
/// <summary> /// 回收站信息 /// </summary> public class RecycleBinInfo { public long NumItems { get; set; } public long Size { get; set; } } /// <summary> /// 获取回收站大小和文件个数 /// </summary> /// <param name="RBsize"></param> /// <param name="RBNumItems"></param> /// <returns></returns> public static RecycleBinInfo GetRecycleBinInfo() { SHQUERYRBINFO info = new SHQUERYRBINFO(); info.cbSize = (uint)Marshal.SizeOf(info); if (SHQueryRecycleBin(null, ref info) == 0) { return new RecycleBinInfo() { Size = info.i64Size, NumItems = info.i64OriginalSize }; } return new RecycleBinInfo() { Size = 0, NumItems = 0 }; } [DllImport("shell32.dll")] private static extern int SHQueryRecycleBin(string pszRootPath, ref SHQUERYRBINFO pqrbi); [StructLayout(LayoutKind.Explicit, Size = 40)] private struct SHQUERYRBINFO { [FieldOffset(0)] public uint cbSize; [FieldOffset(4)] public uint i64Size; [FieldOffset(12)] public uint i64OriginalSize; [FieldOffset(16)] public uint dwItems; [FieldOffset(20)] public uint uDriveType; [FieldOffset(24)] public uint uDriveSerialNumber; [FieldOffset(28)] public uint uFileFlags; [FieldOffset(32)] public uint uFileAttributes; [FieldOffset(36)] public uint dwVolumeFlags; }
uint 换成 ulong
[FieldOffset(4)] public ulong i64Size;
[FieldOffset(12)] public ulong i64OriginalSize;
谢谢,搞定了。。。
[StructLayout(LayoutKind.Explicit)]
private struct SHQUERYRBINFO
{
[FieldOffset(0)] public ulong cbSize;
[FieldOffset(8)] public ulong i64Size;
[FieldOffset(16)] public ulong i64OriginalSize;
}
你用这个调试一下看看. 我看了下,应该是cbSize的大小在64和86上不一样
[StructLayout(LayoutKind.Explicit, Size = 32)]
private struct SHQUERYRBINFO
{
[FieldOffset(0)] public uint cbSize;
[FieldOffset(4)] public uint _1;
[FieldOffset(8)] public uint _2;
[FieldOffset(12)] public uint _3;
[FieldOffset(16)] public uint _4;
[FieldOffset(20)] public uint _5;
[FieldOffset(24)] public uint _6;
[FieldOffset(28)] public uint _7;
[FieldOffset(32)] public uint _8;
}
谢谢,已经搞定了啊。。。
32为是4个字节,偏移量是4;而64位是8个字节,偏移量是8;我上面已经贴出代码了啊。声明那个。。。