How use win32 dll in c#
-
Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake
-
Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake
ashish8patil wrote:
in that folder i put trydll.dll,trydll.lib .
Is that the working directory of your application ? Make sure this is the case. I'm not a C# expert but I suppose you can find that in the project options.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
ashish8patil wrote:
in that folder i put trydll.dll,trydll.lib .
Is that the working directory of your application ? Make sure this is the case. I'm not a C# expert but I suppose you can find that in the project options.
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++yes i put it in working dir
-
Hello All , I create win32 dll .with simple function Add(int,int). using dumpbin i can see add function is in my dll. Then i create new c# console application. in that folder i put trydll.dll,trydll.lib . then in .cs file i add using System.Runtime.InteropServices; my class was like this ------ class Program { [DllImport("trydll.dll")] public static extern int Add(int a, int b); static void Main(string[] args) { int c; //int a=2; c = Add(5, 6); Console.Write(c); } } ------- when i run prog .i get run time exception \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'trydll.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at dlltry.Program.Add(Int32 a, Int32 b) at dlltry.Program.Main(String[] args) in C:\Documents and Settings\........ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ What is my mistake
you need to put the mangled name for the function. [DllImport("/*put the path of the dll*/")] public static extern int Add/*mangled function name instead of Add*/(int a, int b);
You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_