I have a C# form application...i created a Dll...now i want to launch that dll using this program. how do i do it?
#include
typedef int (*
To do what your code example does, use the following C# code:
public static class DllHelper
{
[System.Runtime.InteropServices.DllImport("Dll1.dll")]
public static extern int function1();
}
private void buttonStart_Click(object sender, EventArgs e)
{
try
{
DllHelper.function1();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
The above example is a C# program that calls a function in non .NET based DLL. The example below is a C# program that calls a function in a .NET based DLL.
try
{
System.Reflection.Assembly dll1 = System.Reflection.Assembly.LoadFile("Dll1.dll");
if (dll1 != null)
{
object obj = dll1.CreateInstance("Function1Class");
if (obj != null)
{
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("function1");
mi.Invoke(obj, new object[0]);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Is any of the the 2 examples what you want? Or are you trying to call a C# function in a DLL from your example code?