0

旧项目的回归,需要使用 VB6。我在引用旧 VB6 IDE 中包含 System.IO 的适当 DLL 时遇到问题。

我曾尝试参考:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll - 错误:无法添加对指定文件的引用

添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb 的引用 - 不起作用。

添加了对 C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb 的引用 - 没有来自智能感知的 System.IO。

在此处输入图像描述

有人可以发布分步说明吗?

4

1 回答 1

0

得到这个有点工作:

Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

Dim info As DiskInformation
Dim lAnswer As Long
Dim lpRootPathName As String
Dim lpSectorsPerCluster As Long
Dim lpBytesPerSector As Long
Dim lpNumberOfFreeClusters As Long
Dim lpTotalNumberOfClusters As Long
Dim lBytesPerCluster As Long
Dim lNumFreeBytes As Double
Dim dPercentFreeClusters As Double
Dim sString As String

lpRootPathName = "c:\"
lAnswer = GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters)
lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector

' Throws overflow exception - I guess there were no Terabyte drives when VB6 came around
' lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters

'sString = "Number of Free Bytes : " & lNumFreeBytes & vbCr & vbLf
'sString = sString & "Number of Free Kilobytes: " & (lNumFreeBytes / 1024) & "K" & vbCr & vbLf
'sString = sString & "Number of Free Megabytes: " & Format(((lNumFreeBytes / 1024) / 1024), "0.00") & "MB"

dPercentFreeClusters = Round(lpNumberOfFreeClusters / lpTotalNumberOfClusters * 100, 2)

但是,Overflow在尝试计算空闲字节数时会引发异常。

我想让这个工作My.Computer.FileSystem。建议?

于 2018-08-17T16:35:08.523 回答