J
jebelsea
how to use dl file in C# ,and show a example to it ,thanks!!
Andreas Håkansson said:Please note that it is not always as trivial as this example. You will have
to examine how you will call the API, for example it may enable you to
pass NULL instead of a reference to a struct (and a struct may be passed
by using Out or Ref, depending how the API will use the struct) which
will change the signature of your interop call.
Another issue are strings. C/C++ have a whole army of different string
types and you need to be aware of this when you pass a string to an
API. You can also use the StringBuilder in some situations where you
expect a buffer to be filled by the API.
This is why I recommend that you read the documentation which is
shipped with .NET Framework and is avalible on MSDN if you don't
have it installed.
Hope this helps,
// Andreas
MuZZy said:Here is an example:
[DllImport("gdiplus.dll", ExactSpelling=true)]
internal static extern int GdipCreateBitmapFromGdiDib( IntPtr bminfo,
IntPtr pixdat, ref IntPtr image );
I didn't call dll's from C# myself, but above is an example of calling a
system func.
Code is taken from Twain Library iinterface ported to C#, which i use for
scanning capability in my app.
jebelsea said:thanks all of above!!!
i find a example ,and take it show!!!
/////===============test.cs file=============================
using System;
using System.Runtime.InteropServices;//this is important!!!
public class InvokeDll {
[DllImport("MyLib.dll", CharSet=CharSet.Auto)]
static extern int add(int a,int b);//interface of out dll file
public static void Main() {
Console.WriteLine(add(10,30));
}
}
///==================================================
///=================mylib.c file=================================
__declspec(dllexport) int __cdecl add(int, int);
int add(int a,int b) {
return a+b;
}
///==================================================
MuZZy said:Here is an example:
[DllImport("gdiplus.dll", ExactSpelling=true)]
internal static extern int GdipCreateBitmapFromGdiDib( IntPtr bminfo,
IntPtr pixdat, ref IntPtr image );
I didn't call dll's from C# myself, but above is an example of calling a
system func.
Code is taken from Twain Library iinterface ported to C#, which i use for
scanning capability in my app.