Call C# functions in C++


I’m trying to use the Bing Speech API in my Project. They have some examples using REST-API here: GitHub - Azure-Samples/SpeechToText-REST: REST Samples of Speech To Text API
Because there are only examples using C#, curl and java I thought about creating a C# dll and calling the functions from C++. I would prefer to use C++ only, but I really don’t know how to
do these HTTP requests in C++…
Can you guys help me? Or maybe suggest a better way to do this?

I created a C# dll with UnmanagedExports:

namespace SpeechRecognition
    public class Class1
        [DllExport("TestFunction", CallingConvention = CallingConvention.StdCall)]
        static public void TestFunction()


        [DllExport("Calc", CallingConvention = CallingConvention.StdCall)]
        static string Calc(int a)
            return a.ToString();

And then I tried to call “Calc” from C++:

typedef const char*(*_Calc) (int a);
    FString filePath = FPaths::Combine(*FPaths::ProjectPluginsDir(), TEXT("VoiceRecognition.dll"));

    void *DLLHandle = NULL;
        DLLHandle = FPlatformProcess::GetDllHandle(*filePath);
    if(DLLHandle != NULL)
        _Calc DLLFuncPtr = NULL;
        FString procName = "Calc";
        DLLFuncPtr = (_Calc)FPlatformProcess::GetDllExport(DLLHandle, *procName);

        if(DLLFuncPtr != NULL)
            const char* result = DLLFuncPtr(2);

But the DLLFuncPtr always returns null. I don’t know why. Also when I export the DLL and open it with a DLL Viewer, I can’t see any functions? Am I doing something wrong?

Why not just use the web request API in unreal?

Went down the “C++ DLL in C++” rabbit hole a few times. Its usually a nightmare on the C++ side especially when debugging.

Its actually far easier to use a messaging system. If the Unreal web request API works then use that.

I didn’t even know that it existed lol.
Thanks guys, I’ll have a look :slight_smile: