467,134 Members | 1,155 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,134 developers. It's quick & easy.

Invoke some functions from Win32Api

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, ;
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.
Nov 16 '05 #1
  • viewed: 1654
2 Replies
using System;
using System.Runtime.InteropServices;
#region how use this?
string sVol = GetVolOf("C");
public class getvol{

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 + @":\",
ref retVal,

return retVal.ToString("x");

Nov 16 '05 #2
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.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Matt Smith | last post: by
5 posts views Thread by Gary Richardson | last post: by
1 post views Thread by r | last post: by
reply views Thread by Mike | last post: by
14 posts views Thread by luc.saffre@gmail.com | last post: by
1 post views Thread by reginpc | last post: by
1 post views Thread by tkpmep@hotmail.com | last post: by
1 post views Thread by Michiel Overtoom | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.