2003.09.22 07:01 "[Tiff] (no subject)", by Rob van den Tillaart
Hi Ryan,
Just started with C# myself, so not an expert opinion. (except for an exercise at a course no experience with this topic)
It is possible to use libraries written in C/C++ from C#. In dotnet vocabulary it is called "unmanaged code".
To use unmanaged code you must use a statement like this:
[DllImport("msvcrt.dll", CharSet=CharSet.Ansi)]
public static extern int puts(String s);
static void Main()
{
String message = "just some message";
puts(message);
}
Often you will also need the "MarshallAs" attribute. This attribute can be used with a field in a class or struct, or with a parameter of a method or to handle the returnvalue.
>From the win32API: struct example
public struct PAINTSTRUCT
{
public HDC hdc;
public int fErase;
public RECT rcPaint;
public int fRestore;
public int fIncUpdate;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)] public byte rgbReserved;
}
With these 2 terms "DllImport" and "MarshallAs" you must be able to find all relevant details in the manual.
reagrds,
rob tillaart