473,373 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

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, ;
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.
Nov 16 '05 #1
2 1913
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");
}
}

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Smith | last post by:
hi all, again.... having another problem with python COMs, I run a python script on a win2000 machine, that uses win32com.client and it runs perfectly, whereas when I come to run it on a win98...
5
by: Gary Richardson | last post by:
I'm trying to use win32api.SetCursorPos() to position the cursor in a Tkinter canvas window. I.e.: from Tkinter import * import win32api root = Tk() canvas = Canvas(root, width=400,...
1
by: r | last post by:
Hi, Could someone please direct me in the right direction? I would like to p/invoke few functions from user32: DrawAnimatedRects FindWindow, FindWindowEx , GetWindowRect struct RECT how...
2
by: Jim | last post by:
I am trying to figure out how to embed Python in a little C++ Windows console app. Here's the code: // Py_Initialize(); Py_InitializeEx(0); PyRun_SimpleString("from win32com.client import *");...
0
by: Mike | last post by:
Hi. I have Python 2.4 installed on my local machine in c:\Python24. I have also downloaded the python for windows extensions installer pywin32-208.win32-py2.4.exe and installed this to...
14
by: luc.saffre | last post by:
Hello, the simplest way to launch the user's standard mail client from a Python program is by creating a mailto: URL and launching the webbrowser: def...
1
by: reginpc | last post by:
Hi, Please anyone say how to find win32api.py file and where its present?? i am Getting the below error... from win32com.shell import shell File...
1
by: tkpmep | last post by:
I'm running Python 2.5.2 on Windows XP and need to interface with R, so I downloaded the R 2.6.2 statistical package and installed it, and did the same for RPy 1.02 (i made sure I got the version...
1
by: Michiel Overtoom | last post by:
On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote: What are the actions you do and the commands you give, and what is the precise error you get? Greetings, -- "The ability of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.