UE4中调用DLL并提供蓝图接口

本文介绍如何在UE4中创建基于C++的动态链接库(DLL)库,并详细阐述如何在Unreal Engine中调用这些DLL库,同时提供蓝图接口供游戏逻辑使用。
摘要由CSDN通过智能技术生成
好久不写文章啦,主要最近工作略忙,一直木有抽出时间来研究Unreal。
当然啦,也不会亏待大家啦。这次带来的教程有点重磅。。。。
我们讨论如何在Unreal的蓝图中调用我们预定义好的DLL。本教程分为两大部分:

一、如何创建基于C++的DLL库

方法很简单,创建工程时选择Visual C++>Win32,创建的工程名称为 CreateAndLinkDLLTut。之后在工程引导中选择DLL和空工程即可。创建完成之后添加新类。此处命名为CreateAndLinkDLL。工程目录结构如下图:
之后将下面的代码分别粘贴到.h和.cpp文件中,代码如下:
#pragma once  

#define DLL_EXPORT __declspec(dllexport)	//shortens __declspec(dllexport) to DLL_EXPORT

#ifdef __cplusplus		//if C++ is used convert it to C to prevent C++'s name mangling of method names
extern "C"
{
#endif

	bool DLL_EXPORT getInvertedBool(bool boolState);
	int DLL_EXPORT getIntPlusPlus(int lastInt);
	float DLL_EXPORT getCircleArea(float radius);
	char DLL_EXPORT *getCharArray(char* parameterText);
	float DLL_EXPORT *getVector4(float x, float y, float z, float w);

#ifdef __cplusplus
}
#endif


#pragma once

#include "string.h"
#include "CreateAndLinkDLLFile.h"


//Exported method that invertes a given boolean.
bool getInvertedBool(bool boolState)
{
	return bool(!boolState);
}

//Exported method that iterates a given int value.
int getIntPlusPlus(int lastInt)
{
	return int(++lastInt);
}

//Exported method that calculates the are of a circle by a given radius.
float getCircleArea(float radius)
{
	return float(3.1416f * (radius * radius));
}

//Exported method that adds a parameter text to an additional text and returns them combined.
char *getCharArray(char* parameterText)
{
	char* additionalText = " world!";

	if (strlen(parameterText) + strlen(additionalText) + 1 > 256)
	{
		return "Error: Maximum size of the char array is 256 chars.";
	}

	char combinedText[256] = "";

	strcpy_s(combinedText, 256, parameterText);
	strcat_s(combinedText, 256, additionalText);

	return (char*)combinedText;
}

//Exported method that adds a vector4 to a given vector4 and returns the sum.
float *getVector4(float x, float y, float z, float w)
{
	float* modifiedVector4 = new float[4];

	modifiedVector4[
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值