How to add and call third party C++ code with DLL call

Hi all. I have a C++ code that controls a plotter and sends a file to it. The code uses a DLL provided by the plotter manufacturer. The code itself works fine and does its job.
I need to somehow call this code in the Unreal engine when a button is clicked. It would be nice to add it to the MyUserWidget class so that I can call it.
I don’t understand at all how to add this there. I would like to add pure C++ code so that it would simply be called from MyUserWidget.h. The documentation from the manufacturer for working with DLLs is very weak and there is almost nothing in it. There was just a small example of code. I had a hard time figuring it out and wrote this separate code that works well as just an .exe.
Please any help, below is part of my code

#include <windows.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>


typedef HANDLE (APIENTRY *PROC_OPENUSB)(int, int, DWORD);

int main(int argc, char* argv[]) {

	setlocale(LC_ALL, "RU");

	HMODULE hUsbLib = LoadLibrary("OPENUSB.DLL");

	if (hUsbLib == NULL) {
		printf("Ошибка загрузки DLL\n");
		return 0;
	}

	PROC_OPENUSB lpfnOpenUsb = (PROC_OPENUSB)GetProcAddress(hUsbLib, "OpenUsb");

	if (lpfnOpenUsb == NULL) {
		printf("Ошибка: нет доступа к Dll, проверьте разрядность\n");
		return 0;
	}

	HANDLE hWrite = (lpfnOpenUsb)(0, 0, FILE_FLAG_OVERLAPPED);
	HANDLE hRead  = (lpfnOpenUsb)(0, 1, FILE_FLAG_OVERLAPPED);

	if ((hWrite == INVALID_HANDLE_VALUE) || (hRead == INVALID_HANDLE_VALUE)) {
		if (hWrite != INVALID_HANDLE_VALUE)
			CloseHandle(hWrite);

		if (hRead != INVALID_HANDLE_VALUE)
			CloseHandle(hRead);

		printf("Не удалось найти устройство, проверьте подключение\n");
		return 0;
	}

	OVERLAPPED WriteEvt{}, ReadEvt{};

	WriteEvt.hEvent     = CreateEvent(NULL, TRUE, FALSE, NULL);
	WriteEvt.Offset     = 0;
	WriteEvt.OffsetHigh = 0;
	ReadEvt.hEvent      = CreateEvent(NULL, TRUE, FALSE, NULL);
	ReadEvt.Offset      = 0;
	ReadEvt.OffsetHigh  = 0;

	int rc = 1;

	std::vector<char> szBuffer(64);
	std::vector<char> szCommand(128);
	DWORD dw;
	BOOL bSuccess;


UPD: I have successfully imported the DLL into UE5 and it loads fine. But I still don’t know how to rewrite the rest of the code to work in UE5. I found some tutorials on loading Dlls on the UE Wiki https://unreal.gg-labs.com/wiki-archives/devops/linking-dlls
And also from the guy who connected the gamepads Unreal Engine 4 • Просмотр темы - Два геймпада XInput (text in Russian)
PS: If something is not clear, I apologize for my English, I’m from Kazakhstan)))

Did you create a class derived from BlueprintFunctionLibrary to expose the dll interaction to blueprints / unreal c++?

Now I have created a BlueprintFunctionLibrary class. So far I only have two functions in the .h document: loading and unloading Dll. And it works, UE5 loads and unloads. Now I’m still thinking about how to transfer the rest of the code. I’m almost new to writing code in UE

#include "MyBlueprintFunctionLibrary.h"

void* v_dllHandle;

bool UMyBlueprintFunctionLibrary::importDLL(FString folder, FString name)
{
    FString filePath = *FPaths::ProjectPluginsDir() + folder + "/" + name;

    if (FPaths::FileExists(filePath))
    {
        v_dllHandle = FPlatformProcess::GetDllHandle(*filePath); // Retrieve the DLL.
        if (v_dllHandle != NULL)
        {
            return true;
        }
    }
    return false;   // Return an error.
}

void UMyBlueprintFunctionLibrary::freeDLL()
{
    if (v_dllHandle != NULL)
    {
        FPlatformProcess::FreeDllHandle(v_dllHandle);
        v_dllHandle = NULL;
    }
}

I was able to get the tutorial a 100% running. Do you have a list of commands that are accessible inside of the DLL file?

Is it accessible somewhere on github?

I’m guessing it’s in one of the drivers here?

Or
https://www.silhouetteamerica.com/

The origin seems hard to track down. Could you send it in a pm for tests?

You may need to push it through a DLL decompiler to see the internal methods.

I wrote to you in private messages