Download

GetDllExport returning NULL

Hello,

I am trying to export a function in my **.dll **file located in myProject/Plugins directory.
My **importDLL **function is returning TRUE indicating it obtained the DLL file.
However, **GetDllExport **highlighted in red below is failing! (IE. returning false)
I followed this tutorial exactly: https://wiki.unrealengine.com/Linking_Dlls

The function I am calling from my DLL is known as int chamber(int bullet) which returns a number 1.



//blueprint function library.cpp

#include "BP_BlueprintFunctionLibrary.h"

typedef int(*_getchamberInt)(int intStore); 
_getchamberInt m_getchamberIntFromDll;

bool UBP_BlueprintFunctionLibrary::importDLL(FString folder, FString name)  //imports the DLL file 
{
    FString filePath = *FPaths::GamePluginsDir() + folder + "/" + name; //optional
    v_dllHandle = FPlatformProcess::GetDllHandle(*filePath); // Retrieve the DLL.
    if (v_dllHandle != NULL)
    {
            return true;
    }
    else
    {
        v_dllHandle = FPlatformProcess::GetDllHandle(*name);
        if (v_dllHandle != NULL) {
            return true;
        }
        else {
            return false;    // Return an error
        }
    }
}
bool UBP_BlueprintFunctionLibrary::importMethodchamber() { //imports the method from the DLL

    if (v_dllHandle) {

        m_getchamberIntFromDll = NULL;
        FString procName = "chamber";
        m_getchamberIntFromDll = (_getchamberInt)FPlatformProcess::GetDllExport(v_dllHandle, *procName);
        if (m_getchamberIntFromDll != NULL) {
            return true;
        }
    }
    return false;
}

this is my **.h **header from my DLL


#pragma once

#ifdef DLL1_EXPORTS
#define DLL1_API _declspec(dllexport)
#else
#define DLL1_API _declspec(dllimport)
#endif

#ifdef _cplusplus
extern "C"
{
#endif

           DLL1_API int chamber(int bullet);

#ifdef _cplusplus
}
#endif


after 2 days of troubleshooting and debugging, I finally found the solution after reading this:

I simply got rid of :

#ifdef c_plusplus
extern “C” { }
#endif

and simply included it to my function in my **.h **file.

extern “C” DLL1_API int chamber(int bullet);

I can’t believe it. Seriously.