UE4 静态库导入Custom HID

UE4 静态库导入Custom HID

简介

有时候需要为ue4增加一些额外的功能,比如CustomHID读写
这个时候就需要从外部导入静态库或者动态库(此例子是静态库)

初始工作

新建C++项目,在项目目录创建Lib文件夹并把lib放入此文件夹。如图:
在这里插入图片描述
在这里插入图片描述

CS文件

打开CS文件并修改
在这里插入图片描述

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.IO;
public class custom_hidue4 : ModuleRules
{
    private string ModulePath
    {
        get { return ModuleDirectory; }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../")); }
    }
    public custom_hidue4(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
	
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

		PrivateDependencyModuleNames.AddRange(new string[] {  });

        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Lib"));
        //PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath,"Lib/", "custom_usbdll.lib"));
        PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "Lib/", "hidapi.lib"));
        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    }
}

代码需根据自己情况与需求进行修改

使用方式

演示的是使用蓝图库创建的:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CustomHID.generated.h"

/**
 * 
 */
UCLASS()
class CUSTOM_HIDUE4_API UCustomHID : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintCallable, Category = "HID")
		static int read_usbhid(TArray<uint8> &data);
	UFUNCTION(BlueprintCallable, Category = "HID")
		static int write_usbhid(TArray<uint8> data);
};

// Fill out your copyright notice in the Description page of Project Settings.


#include "CustomHID.h"

unsigned char *read(int* len);
int write(unsigned char *data, int len);


int UCustomHID::read_usbhid(TArray<uint8> &data)
{
	int len;
	unsigned char *dat = read(&len);
	if (dat == nullptr)
		return 0;
	for (int i = 0; i < len; i++)
		data.Add(dat[i]);
	return len;
}

int UCustomHID::write_usbhid(TArray<uint8> data)
{
	unsigned char *dat = new unsigned char[data.Num()];
	for (int i = 0; i < data.Num(); i++)
		dat[i] = data[i];
	return write(dat, data.Num());
}

其他

例子中用的hidapi.lib在下面
https://blog.csdn.net/weixin_41738734/article/details/103596404

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值