I would like to use a C# DLL in an Android Project that is developing by Java (Not Xamarin or Mono). My first strategy to solve this contains these steps:
- Create a C++ usable DLL by DllExport from the C# code. (create a C++ wrapper for C# code)
- Create a .so library from the C++ project that uses generated DLL from the previous step.
So I've used the DLLExport (https://github.com/3F/DllExport)
C# Side:
namespace NumbersLibCS
{
public class Math
{
public Math()
{
}
[DllExport]
public static int GetRandomEvenNumber()
{
var rnd = new Random();
int n = rnd.Next(1, 1000 ) * 2;
return n;
}
}
}
But in C++ to use the generated DLL I think I should use just windows.h library that is not available on the Android OS:
#include <windows.h>
typedef int(__cdecl *GetRandomEvenNumber)();
int main(){
HMODULE lib = LoadLibrary("mycsharp.dll");
auto getRndNumber= (GetRandomEvenNumber)GetProcAddress(lib, "GetRandomEvenNumber");
int c = getRndNumber();
}
Now here are my questions:
- How can I use DLLExport generated DLL without windows.h?
- Can I use .NetCore 2.0 to achieve this without using DLLExport?