# Call C# functions in C++

**URL:** <https://forums.unrealengine.com/t/call-c-functions-in-c/115593>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 28, 2018, 11:37am UTC](https://forums.unrealengine.com/t/call-c-functions-in-c/115593 "2018-08-28T11:37:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SenseiHaketon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SenseiHaketon](https://forums.unrealengine.com/u/SenseiHaketon)\
**Post date:** [August 28, 2018, 11:37am UTC](https://forums.unrealengine.com/t/call-c-functions-in-c/115593/1 "2018-08-28T11:37:09Z")

</div>

Hi!

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](https://github.com/Azure-Samples/SpeechToText-REST)  
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:

```auto

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++:

```auto

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

    void *DLLHandle = NULL;
    if(FPaths::FileExists(filePath))
    {
        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?

---

<div class="post-metadata">

**Author:** ![Zeblote](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zeblote](https://forums.unrealengine.com/u/Zeblote)\
**Post date:** [August 28, 2018, 12:04pm UTC](https://forums.unrealengine.com/t/call-c-functions-in-c/115593/2 "2018-08-28T12:04:24Z")

</div>

Why not just use the web request API in unreal?

---

<div class="post-metadata">

**Author:** ![Shmoopy1701](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shmoopy1701/32/1194536_2.png) [@Shmoopy1701](https://forums.unrealengine.com/u/Shmoopy1701)\
**Post date:** [August 28, 2018, 2:05pm UTC](https://forums.unrealengine.com/t/call-c-functions-in-c/115593/3 "2018-08-28T14:05:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SenseiHaketon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SenseiHaketon](https://forums.unrealengine.com/u/SenseiHaketon)\
**Post date:** [August 28, 2018, 2:54pm UTC](https://forums.unrealengine.com/t/call-c-functions-in-c/115593/4 "2018-08-28T14:54:16Z")

</div>

> [@Zeblote](#):
>
> Why not just use the web request API in unreal?

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