Invoke some functions from Win32Api

N

Nurchi BECHED

Hello, my dearest respected brother, All!

How do you make calls to Win32Api functions from C#
I have an old example in Visual FoxPro...
Kind of need to do the same in C# now...
I need to get volume information (as much as possible)
I am sure .Net Framework has already got something to
do with it, but I am also interested (in learning purposes)
how to do the same using Win32Api.
Here goes a part of Visual FoxPro example:
----------------------------------------------------------
lpRoot = "C:\"
lpVolName = SPACE(256)
nVolSize = 256
lpVolNumber = 0
lpMaxComp = 256
lpFlags = 0
lpFSName = SPACE(256)
nFSSize = 256

DECLARE INTEGER GetVolumeInformation ;
IN Win32API AS GetVolInfo ;
STRING @lpRoot, ;
STRING @lpVolName, ;
INTEGER nVolSize, ;
INTEGER @lpVolNumber, ;
INTEGER @lpMaxComp, ;
INTEGER @lpFlags, ;
STRING @lpFSName, ;
INTEGER nFSSize
lnRet=GetVolInfo(@lpRoot, @lpVolName, ;
nVolSize, @lpVolNumber, ;
@lpMaxComp, @lpFlags, ;
@lpFSName, nFSSize)
----------------------------------------------------------
Semicolons in FoxPro mean that the next line continues
a previous one.
Like each semicolon can be replaced with the next line.
'@' means a reference parameter.
And this is a working example (part of it). There are no errors...

Thanks in advance.

With best regards, Nurchi BECHED.
 
G

Guest

using System;
using System.Runtime.InteropServices;
#region how use this?
/*
string sVol = GetVolOf("C");
*/
#endregion
....
public class getvol{

[DllImport("kernel32.dll")]
private static extern int GetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);

public static string GetVolOf(string drvID){
const int MAX_FILENAME_LEN = 256;
int retVal = 0;
int a =0;
int b =0;
string str1 = null;
string str2 = null;


int i = GetVolumeInformation(
drvID + @":\",
str1,
MAX_FILENAME_LEN,
ref retVal,
a,
b,
str2,
MAX_FILENAME_LEN
);

return retVal.ToString("x");
}
}
 
N

Nurchi BECHED

Hello, noahart!

Thank you very much.
I just didn't know which dll to use.
Thanks again.

You wrote on Sun, 19 Sep 2004 20:31:02 -0700:

n> [DllImport("kernel32.dll")]
n> private static extern int GetVolumeInformation(
....

With best regards, Nurchi BECHED.
 

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