UE4引用c#导出dll

近期收到一个语音识别需求,查阅一系列资料测试后,ue可使用的识别插件精度感人,但是unity的语音识别精度在可接受范围内,经过查询unity调用的Windows.Media.SpeechRecognition,属于uwp层面,各种资料都是c#,那么能不能用c#封装导出给c++呢,所以有了这条博文

 

新建一个类库

项目中–管理NuGet程序包,添加UnmanagedExports

 

编写导出代码

using System.Runtime.InteropServices;
using RGiesecke.DllExport;

namespace dllforue4
{
    internal class testdll
    {
        [DllExport("GetStr", CallingConvention = CallingConvention.StdCall)]
        static public string Getstr(string path)
        {
            string str = "hello";
            return str + path;
        }

    }
}

进行编译

 

在ue4中调用  创建一个c++蓝图方法库

bool UCreateAndLinkDLLTutBFL::importDLL(FString folder, FString name)
{
	FString filePath = *FPaths::GamePluginsDir() + folder + "/" + name;
	
	if (FPaths::FileExists(filePath))
	{
		v_dllHandle = FPlatformProcess::GetDllHandle(*filePath); // Retrieve the DLL.
		if (v_dllHandle != NULL)
		{
			typedef char* (*_GetDomain)(char*);
			_GetDomain DLLFuncPtr = NULL;
			FString procName = "GetStr";
			DLLFuncPtr = (_GetDomain)FPlatformProcess::GetDllExport(v_dllHandle, *procName);
			if (DLLFuncPtr != NULL)
			{
				char* input = "hello, test info";
				char* result = DLLFuncPtr(input);
				//GEngine->AddOnScreenDebugMessage(-1, 20.0, FColor::Red, input);
				GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Red, result);
				return true;
			}
			return true;
		}
	}
	return false;	// Return an error.
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值