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)))