mBajema mBajema - 3 months ago 20
C# Question

EntryPointNotFoundException in one DLL while seems fine in another

I have two DLLs that I created and they reside in Assets/Plugins. One seems to be working fine, the other gives me an EntryPointNotFoundException even though the code look exactly the same to me. Maybe there's some setting I missed in VisualStudio? What settings do I need?

The one that works looks like this:

C#

[DllImport("winBlinkDetect")]
private static extern void IsSeven(ref int x);

[DllImport("winBlinkDetect")]
private static extern int PrintFive();

void Start()
{
int test = 0;
Debug.Log("x = " + test);
IsFive(ref test);
Debug.Log("x = " + test);
Debug.Log(PrintFive());
}


C++ Header

#if _MSC_VER // this is defined when compiling with Visual Studio
#define EXPORT_API __declspec(dllexport) // Visual Studio needs annotating exported functions with this
#define _USE_MATH_DEFINES
#else
#define EXPORT_API // XCode does not need annotating exported functions, so define is empty
#endif

#ifdef __cplusplus
extern "C" {
#endif

void EXPORT_API IsFive(int *y);
void EXPORT_API IsSeven(int *x);
int EXPORT_API PrintFive();


#ifdef __cplusplus
}
#endif
C++ .cpp

void IsFive(int *y)
{
*y = 5;
}

void IsSeven(int *x)
{
*x = 7;
}

int PrintFive()
{
return 99;
}


For the one that doesn't work:
C#

[DllImport("brain")]
private static extern int GiveNinetyNine();

[DllImport("brain")]
private static extern void IsFive(ref int x);

void Start()
{
int test = 0;
Debug.Log("x = " + test);
IsFive(ref test);
Debug.Log("x = " + test);
Debug.Log(GiveNinetyNine());
}


C ++ Header

#if _MSC_VER // this is defined when compiling with Visual Studio
#define EXPORT_API __declspec(dllexport) // Visual Studio needs annotating exported functions with this
#define _USE_MATH_DEFINES
#else
#define EXPORT_API // XCode does not need annotating exported functions, so define is empty
#endif

#include <string>;

#ifdef __cplusplus
extern "C" {
#endif

// test functions
void EXPORT_API IsFive(int *y);
void EXPORT_API IsSeven(int *x);
int EXPORT_API GiveNinetyNine();
#ifdef __cplusplus
}
#endif
C++ .cpp

void IsFive(int *y)
{
*y = 5;
}

void IsSeven(int *x)
{
*x = 7;
}

int GiveNinetyNine()
{
return 99;
}

Answer

Dependency Walker shows no exported functions, but exported functions in header file looks good. Seems the h file is not included into the cpp file. To check this put __declspec(dllexport) inside cpp in function definition.