Calling unmanaged DLL in C#.NET

I have a project that created a DLL but somehow I wanted to know if the current DLL I have is the same with the project. So, I created a form project in C# and calling the function. Sample below:

using System.Windows.Forms;
using System.Runtime.InteropServices; // DllImport

namespace DLLTester
{
  public partial class Form1 : Form
{
 public Form1( )
{
   InitializeComponent();
}

  private void button1_Click( object sender, EventArgs e )
 {
     MessageBox.Show(WrapperClassOfDLL .EnableDevice().ToString());
 }
}

public class WrapperClassOfDLL {

[DllImport("MyUnmanagedDLL.dll")]

public static extern UInt32 GetVersion( );

}
}

Put the DLL in the project directory and make sure the function signature is the same in the DLL.

That's it!

Comments

Popular posts from this blog

C++: Type Conversions

How to asynchronously update GUI in Java