I'm trying to include a dll into unreal engine 4. So until now, I'm just trying to print a string coming from the DLL. But when i try to use the function of the DLL i immediatly got this error:
Exception thrown at 0x00007FFACC964C80 in (UE4Editor-Prototype.dll) in UE4Editor.exe: stack cookie instrumentation code detected a stack-based buffer overrun
I've check that the issue really come from the function call, if i remove it, I don't get the error. I've try to put it in a char, string or even nothing but it didn't do anything. I've tried to catch the error but it never succeed, unreal just crash. I succeed to get the error with visual studio debugger. When i go step by step. i can see, the DLL is found but after BeginPlay, it crash.
Here is the code in unreal which is not working:
void UMyTestComponent::BeginPlay()
{
Super::BeginPlay();
//It's just some test code, i know it's executed once, this code appears
//inside the log
UE_LOG(LogTemp, Warning, TEXT("TEEEEEEEEEEEEEEEEEST1"));
try {
//Call to the DLL, this call make UE4 crash
Test_init();
}
catch (std::exception e) {
//Nothing is ever written here
UE_LOG(LogTemp, Warning, TEXT("%s"), e.what());
}
}
here is my Dll file .h
#pragma once
#include <string>
#define PARSER_API __declspec(dllexport)
extern PARSER_API std::string Test_init();
and here is my Dll file .cpp
#include "pch.h"
#include <utility>
#include <limits.h>
#include <iostream>
#include "Test.h"
std::string Test_init()
{
return std::string("DLLLLLLLL");
}
I'm working on windows 10, UE 4.22.3 and visual studio 2019
The goal would be to catch the string and to print it in an : UE_LOG() to print it. So i will print "DLLLLL" just to check the correct linkage
Edit: I've tried several formatting with __declspec(dllexport). but none is working, the C linkage too.