API Function Call - GetFreeDiskSpace

B

bill_morgan

Friends,

I am running Excel 2000 on Win XP.

I created a VBA User Defined Function that references the follwing API
function:

Private Declare Function GetDiskFreeSpace Lib "kernel32" _
(ByVal lpRootPathName As String, lpSectorsPerCluster As _
Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As _
Long, lpTotalNumberOfClusters As Long) As Long

Question: Code seems to be working okay (I have serveral other API calls in
the same module), but I am getting Runtime Error 453 "Can't Find DLL Entry
Point in Kernal 32"

Has the name of the DLL changed since Win 2000? How do I need to change the
above API function declaration so that it is referencing the right DLL?

Thanks for your help ...

Bill Morgan
(e-mail address removed)
 
S

sebastienm

Hi,
Maybe try to declare with the Alias "GetDiskFreeSpaceA":

Public 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
 
B

bill_morgan

Perfect solution. Thank you ...

sebastienm said:
Hi,
Maybe try to declare with the Alias "GetDiskFreeSpaceA":

Public 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
 
D

Dave Peterson

Another option:

Option Explicit
Sub testme()

Dim myDriveLetter As String


' With a reference (tools|references) to microsoft scripting runtime
' Dim FSO As Scripting.FileSystemObject
' Dim myDrive As Scripting.Drive
' Set FSO = New Scripting.FileSystemObject

' without that reference
Dim FSO As Object
Dim myDrive As Object
Set FSO = CreateObject("scripting.filesystemobject")

myDriveLetter = "C"
Set myDrive = FSO.GetDrive(myDriveLetter)
MsgBox Format(myDrive.freeSpace, "0,000")


End Sub

sub testme02()
'or just this:
Dim myDriveLetter As String

myDriveLetter = "C"
MsgBox CreateObject("scripting.filesystemobject") _
.GetDrive(myDriveLetter).freeSpace

end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top