vs dll不是有效的win32应用程序_【小功能】UE4中调用DLL并提供蓝图接口

8b68f9a22556b1869c3d39c3292456ed.png

后续文章更新移步→微信公众号“虚幻社区”(mantra-xhsq),您的支持是我创作的动力。

我们讨论如何在Unreal的蓝图中调用我们预定义好的DLL。本教程分为两大部分:

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

方法很简单,创建工程时选择Visual C++>Win32,创建的工程名称为CreateAndLinkDLLTut。之后在工程引导中选择DLL和空工程即可。创建完成之后添加新类。此处命名为CreateAndLinkDLL。工程目录结构如下图:

c9d0ad34c9d5694a4837d36e16d5383a.png

之后将下面的代码分别粘贴到.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, flo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值