Call c# dll functions in c++

I am trying to call c# dll functions in c++.
Problem is that FPlatformProcess::GetDllExport() returns null.

This is c# code.

[DllExport("Add", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static public int Add(int a, int b)
{
        return a + b;
}

This is c++ code.

void* DllHandle = nullptr;

if (DllHandle == nullptr)
{
	typedef int(*_Add)(int a, int b);
	FString DllPath = FPaths::Combine(*FPaths::ProjectPluginsDir(), TEXT("AndroidAPITemplate/ThirdParty/AllegWifi/"), TEXT("ClassLibrary1.dll"));

	if (FPaths::FileExists(DllPath))
	{
		DllHandle = FPlatformProcess::GetDllHandle(*DllPath);

		if (DllHandle)
		{
			_Add Add = nullptr;
			FString ProcName = "Add";
			Add = (_Add)FPlatformProcess::GetDllExport(DllHandle, *ProcName);

			if (Add)
				return Add(2, 2);
		}
	}
}
FPlatformProcess::FreeDllHandle(DllHandle);
DllHandle = nullptr;
return 100000;

I already tried it but it didn’t work.

Did you ever figure this out? I’m trying to do something similar.

Remember to set the C# project’s Platform Target to x64 (or x86), because “Any CPU” won’t work.

Chances are your exported symbol has added decoration and is not as plain as “Add”, so GetProcAddress (which is used by GetDllExport) doesn’t find it.
Open your dll with some dump tool like DependencyWalker to get the full exported symbol.
It may look something like ?Add@@@UEAAHXZ@XZ.