473,403 Members | 2,284 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,403 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 1917
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.