Reputation: 11
I tried to call the function from .dll file using java native interface ,its successfully working, But I don't know how to call function from .dll using C# ,please advice me on this.
Upvotes: 1
Views: 341
Reputation: 1979
I like the link provided by Baldrick for DllImport attribute.
This is what I recommend.
Download Dependency Walker (small application exe, no need to install).
Open your DLL in the Dependecy Walker to view the exposed entry points of DLL.
Declare external call to native function in C# like this.
C#:
[DllImport("Your_DLL.DLL", EntryPoint="Function_Entry_Point",CallingConvention=CallingConvention.StdCall)]
static extern IntPtr Function1();
Note:
Upvotes: 0
Reputation: 11840
If it's a native DLL, you need to add a DLLImport statement, importing the function you want.
The documentation is here.
The attribute looks like this, typically:
[DllImport("YourDllNameHere.dll")]
public static extern int YourFunction(int input);
This will import a function called YourFunction (which takes an int input, and returns an int) from YourDllNameHere.dll.
Upvotes: 1
Reputation: 5804
Add that dll into your project as a referenced dll into reference folder(right click on references ,add reference then "Browse" to you DLL).then it should be available for to use as you want and just use that dll as follows in the code level.
using System;
using YourDllName;
class ExampleClass
{
//you can use your dll functions
}
Upvotes: 0
Reputation: 6105
Let's say your DLL name is MyLibrary
and MyFunction
is the function contain in your DLL .
First right click on your Reference
, browse and add your DLL .
Declare your DLL as a namespace using MyLibrary;
And you can call MyFunction
!
Or
Another way , you can use this msdn reference !
Upvotes: 0
Reputation: 2531
Look at DLLImport attribute in MSDN http://msdn.microsoft.com/en-us/library/aa664436(v=vs.71).aspx
using System;
using System.Runtime.InteropServices;
class Example
{
[DllImport("your_dll_here.dll")]
static extern int SomeFuncion1(int parm);
static void Main()
{
int result = SomeFunction1(10);
}
}
Upvotes: 1