I have a native library written as below.
Hello.h:
#include<iostream>
using namespace std;
class __declspec(dllexport) Hello
{
public:
int PrintHello(char* str);
};
Hello.cpp
#include<iostream>
#include "Hello.h"
using namespace std;
int Hello::PrintHello(char* str)
{
cout<<"Hello "<< str <<endl;
return 0;
}
then wrote some Exposing function
API.h
#include<iostream>
#include"Hello.h"
__declspec(dllexport) Hello* APICreateHello();
__declspec(dllexport) void APIDestroyHello();
API.cpp:
#include<iostream>
#include "API.h"
extern "C" __declspec(dllexport) Hello* __cdecl APICreateHello(char* str)
{
return new Hello();
}
extern "C" __declspec(dllexport) void APIDestroyHello(Hello* obj)
{
delete obj;
}
Dumpbin results in APICreateHello and APIDestroyHello as it is. there is no Name mangling.
Tried accessing using C# main as below but results in EntryPointException.
public class MyCustomDLLWrapper
{
[DllImport("TestLib.dll",EntryPoint = "APICreateHello")]
public static extern IntPtr APICreateHello(string str);
}
namespace TestManagedApp
{
class Program
{ public static int Main(string[] args)
{
IntPtr x = MyCustomDLLWrapper.APICreateHello("Pavan");
return 0;
}
}
}
Please help. Thanks in advance