0

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.

miyoku
  • 107
  • 1
  • 13
  • The question is a bit hard to follow. there are some steps took, that modified the code. The code posted in the question, corresponds to which step? Is it running like this? Does *UE\_LOG* work *OK*? Does the code crash? Can you share more details about your environment (*OS*, build tools, etc.)? One mistake I see in your *.h* file is `__declspec(dllexport)`. Check https://stackoverflow.com/questions/30581837/linker-error-when-calling-a-c-function-from-c-code-in-different-vs2010-project/30583411#30583411. – CristiFati Sep 09 '19 at 09:28
  • Hi thanks for answering, i've edited my question to help you a bit. But to add some other information, the first bloc of code is a sceneComponent, and when the scene start, the function beginPlay is called. Inside this one is the call to a DLL outside the project UE4. this DLL is built in visual studio. – miyoku Sep 09 '19 at 15:50

0 Answers0