Hello,
I created one Mono application to call C method from a shared library in Linux. My code is listed below
using System;
using System.Runtime.InteropServices;
namespace testConsole
{
class MainClass
{
[DllImport("libTest.so",CharSet=CharSet.Auto,CallingConvention =CallingConvention.Cdecl, EntryPoint="testMethod",SetLastError=true ) ]
public static extern void testMethod();
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
testMethod();
Console.WriteLine ("Hello World!");
}
}
}
and my shared library code like this
#ifndef SFLOW_H
#define SFLOW_H 1
#if defined(__cplusplus)
extern "C" {
#endif
void testMethod()
{
}
extern void testMethod1()
{
printf("This from C");
}
#if defined(__cplusplus)
}
#endif
#endif /* SFLOW_H */
And I run the application I can load the library to C# using DllImport. But unable to call its method.How to call that testMethod() function from my mono application ?
Please help me...
The error like this
Hello World!
Unhandled Exception: System.EntryPointNotFoundException: testMethod
at (wrapper managed-to-native) testConsole.MainClass:testMethod ()
at testConsole.MainClass.Main (System.String[] args) [0x0000a] in /home/arun/Projects/testConsole/testConsole/Main.cs:15
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: testMethod
at (wrapper managed-to-native) testConsole.MainClass:testMethod ()
at testConsole.MainClass.Main (System.String[] args) [0x0000a] in /home/arun/Projects/testConsole/testConsole/Main.cs:15
Press any key to continue...