The following code (calling proc DiskFreeSpace) throws an “unbalanced stack” error message.
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
ByVal lpFreeBytesAvailableToCaller As Long, _
ByVal lpTotalNumberOfBytes As Long, _
ByVal lpTotalNumberOfFreeBytes As Long) As Long
Friend Shared Function DiskFreeSpace(ByVal sdirDrive As String) As Long
Dim Status As Long
Dim TotalBytes As Long
Dim FreeBytes As Long
Dim BytesAvailableToCaller As Long
Status = GetDiskFreeSpaceEx(sdirDrive, BytesAvailableToCaller, TotalBytes, FreeBytes)
Return FreeBytes
End Function
What is wrong here?
The exact error message is:
A call to PInvoke function
‘Test!XYZ.Test.FN.MyFileSystem::GetDiskFreeSpaceEx’
has unbalanced the stack. This is
likely because the managed PInvoke
signature does not match the unmanaged
target signature. Check that the
calling convention and parameters of
the PInvoke signature match the target
unmanaged signature.
Additional note: My function does need to work for UNC paths also (local and/or network).
I think your problem in signature. try to use this (from pinvoke):
Difference in returning value