D
David
I am attempting to use the GetDiskFreeSpaceExA api to get the
disksapce for a drive. When I call the function from C#, I receive an
OK rc but the space is for my default drive "c:". No matter what path
(UNC) I pass, I always get the default drive space. I tried passing
the path as a constant, a string, etc., same result. Is there a trick
for UNC in C# or is C(You will bang your head until you hear the
ocean!)
This is the first API I have called from C#, and I may be putting the
DllImport in the wrong area.
Any idea?
Also, when I call this same function from vb6, the result is correct.
Status = GetDiskFreeSpaceEx("\\ATC1\SYS\",
BytesAvailableToCaller, _
TotalBytes, FreeBytes)
public class gSpace
{
[DllImport("kernel32.dll", EntryPoint="GetDiskFreeSpaceExA",
CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetFreeDiskSpaceEx(
[MarshalAs(UnmanagedType.LPTStr)] string lpDirectoryName,
ref long lpFreeBytesAvailable,
ref long lpTotalNumberOfBytes,
ref long lpTotalNumberOfFreeBytes);
public void space()
{
bool rc;
long FreeBytesAvailable = new long();
long TotalNumberOfBytes = new long();
long TotalNumberOfFreeBytes = new long();
String ss = "\\ATC1\SYS\";
rc = GetFreeDiskSpaceEx(ss,ref FreeBytesAvailable, ref
TotalNumberOfBytes, ref TotalNumberOfFreeBytes);
Console.WriteLine("DISK: " + ss + " " + rc + " " +
FreeBytesAvailable + " " + TotalNumberOfBytes + " " +
TotalNumberOfFreeBytes);
}
disksapce for a drive. When I call the function from C#, I receive an
OK rc but the space is for my default drive "c:". No matter what path
(UNC) I pass, I always get the default drive space. I tried passing
the path as a constant, a string, etc., same result. Is there a trick
for UNC in C# or is C(You will bang your head until you hear the
ocean!)
This is the first API I have called from C#, and I may be putting the
DllImport in the wrong area.
Any idea?
Also, when I call this same function from vb6, the result is correct.
Status = GetDiskFreeSpaceEx("\\ATC1\SYS\",
BytesAvailableToCaller, _
TotalBytes, FreeBytes)
public class gSpace
{
[DllImport("kernel32.dll", EntryPoint="GetDiskFreeSpaceExA",
CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetFreeDiskSpaceEx(
[MarshalAs(UnmanagedType.LPTStr)] string lpDirectoryName,
ref long lpFreeBytesAvailable,
ref long lpTotalNumberOfBytes,
ref long lpTotalNumberOfFreeBytes);
public void space()
{
bool rc;
long FreeBytesAvailable = new long();
long TotalNumberOfBytes = new long();
long TotalNumberOfFreeBytes = new long();
String ss = "\\ATC1\SYS\";
rc = GetFreeDiskSpaceEx(ss,ref FreeBytesAvailable, ref
TotalNumberOfBytes, ref TotalNumberOfFreeBytes);
Console.WriteLine("DISK: " + ss + " " + rc + " " +
FreeBytesAvailable + " " + TotalNumberOfBytes + " " +
TotalNumberOfFreeBytes);
}