Click here to Skip to main content
15,904,817 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
logicon8-Nov-08 5:24
logicon8-Nov-08 5:24 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
CPallini8-Nov-08 6:14
mveCPallini8-Nov-08 6:14 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
logicon8-Nov-08 5:35
logicon8-Nov-08 5:35 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
Mark Salsbery8-Nov-08 5:56
Mark Salsbery8-Nov-08 5:56 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
logicon8-Nov-08 6:48
logicon8-Nov-08 6:48 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
Mark Salsbery8-Nov-08 6:51
Mark Salsbery8-Nov-08 6:51 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
logicon10-Nov-08 2:34
logicon10-Nov-08 2:34 
GeneralRe: GetVolumeInformation in a Simple DLL Pin
Luc Pattyn8-Nov-08 5:18
sitebuilderLuc Pattyn8-Nov-08 5:18 
Hi,

in order to call native code (such as a C dll) from managed code (such as C#) you would
need P/Invoke technology. You will have to read up on it.

It starts with a using System.Runtime.InteropServices;

Then you must define the C# prototypes of the methods you are going to use, as in:
[DllImport("kernel32.dll")]
public static extern int GetDiskFreeSpaceEx(string rootPathName,
	ref long lpFreeBytesAvailable, ref long lpTotalNumberOfBytes, 
	ref long lpTotalNumberOfFreeBytes);

and finally call them as if they were real C# methods.
That is, as long as the arguments have simple types such as int.
It becomes rather complex when structures and objects need being passed.
Read-only strings are just fine, writeable strings require a StringBuilder, etc.

Warning1: watch some size differences a long in C is an int in C#, a char in C# is a short in C, ...
Warning2: make sure to have the same calling conventions on both sides. (STDCALL, CDECL, ...)

I have some examples in some of my articles, see e.g. my timers article.
And there is a nice web site on method prototypes at www.pinvoke.net

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Fixturized forever. Confused | :confused:


GeneralRe: GetVolumeInformation in a Simple DLL Pin
logicon8-Nov-08 5:50
logicon8-Nov-08 5:50 
QuestionNeed help with code Pin
dtaylor018-Nov-08 2:57
dtaylor018-Nov-08 2:57 
AnswerRe: Need help with code Pin
David Crow8-Nov-08 3:49
David Crow8-Nov-08 3:49 
AnswerRe: Need help with code Pin
Member 41945938-Nov-08 4:00
Member 41945938-Nov-08 4:00 
QuestionGetTotalHours() ? Pin
Le@rner8-Nov-08 0:59
Le@rner8-Nov-08 0:59 
AnswerRe: GetTotalHours() ? Pin
David Crow8-Nov-08 3:45
David Crow8-Nov-08 3:45 
GeneralRe: GetTotalHours() ? Pin
Le@rner9-Nov-08 19:45
Le@rner9-Nov-08 19:45 
QuestionIs the MFC dead Pin
Jooooe8-Nov-08 0:16
Jooooe8-Nov-08 0:16 
AnswerRe: Is the MFC dead Pin
Cedric Moonen8-Nov-08 0:17
Cedric Moonen8-Nov-08 0:17 
AnswerRe: Is the MFC dead Pin
bob169728-Nov-08 2:55
bob169728-Nov-08 2:55 
AnswerRe: Is the MFC dead Pin
Hamid_RT8-Nov-08 3:27
Hamid_RT8-Nov-08 3:27 
AnswerRe: Is the MFC dead Pin
CPallini8-Nov-08 4:56
mveCPallini8-Nov-08 4:56 
AnswerRe: Is the MFC dead Pin
Mark Salsbery8-Nov-08 6:02
Mark Salsbery8-Nov-08 6:02 
QuestionWindows mobile Pin
Praful Nand N7-Nov-08 22:05
Praful Nand N7-Nov-08 22:05 
QuestionWhy do key-loggers repeat all characters written in Microsoft Word? [modified] Pin
Joseph Marzbani7-Nov-08 20:45
Joseph Marzbani7-Nov-08 20:45 
AnswerRe: Why do key-loggers repeat all characters written in Microsoft Word? Pin
Iain Clarke, Warrior Programmer8-Nov-08 13:02
Iain Clarke, Warrior Programmer8-Nov-08 13:02 
AnswerRe: Why do key-loggers repeat all characters written in Microsoft Word? Pin
Joseph Marzbani8-Nov-08 17:11
Joseph Marzbani8-Nov-08 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.