R
Ravindra Sadaphule
It depends on whether the dll that you wish to use with C# is a COM dll
or win32 dll.
It its a COM dll, then you just add a reference to the dll from Visual
Studio.NET project. It will create Runtime Callable Wrappers and
Unwrappers (COM InterOp) for you. Tou do not need to do any extra
coding.
If its a Win32 dll, then you need to use DllImport attribute in C# for
each function in dll that you wish to expose to C# assembly.
e.g.
Say you have a dll named myLib.dll and you have a function called
Print inside it that you want to expose it to C#, then the code for it
is as follows.
using System;
using System.Runtime.InteropServices;
namespace HelloUtil
{
public class Echo
{
//This is how you register dll function with
//DllImport
[DllImport("myLib.dll")]
static extern void Print(string s);
string myString;
public Echo(string aString)
{
myString = aString;
}
public void Tell()
{
//This is actuall call to dll function
Print(myString);
}
}
}
or win32 dll.
It its a COM dll, then you just add a reference to the dll from Visual
Studio.NET project. It will create Runtime Callable Wrappers and
Unwrappers (COM InterOp) for you. Tou do not need to do any extra
coding.
If its a Win32 dll, then you need to use DllImport attribute in C# for
each function in dll that you wish to expose to C# assembly.
e.g.
Say you have a dll named myLib.dll and you have a function called
Print inside it that you want to expose it to C#, then the code for it
is as follows.
using System;
using System.Runtime.InteropServices;
namespace HelloUtil
{
public class Echo
{
//This is how you register dll function with
//DllImport
[DllImport("myLib.dll")]
static extern void Print(string s);
string myString;
public Echo(string aString)
{
myString = aString;
}
public void Tell()
{
//This is actuall call to dll function
Print(myString);
}
}
}