一个DLL中的EntryPointNotFoundException在另一个DLL中似乎很好

时间:2016-08-17 20:04:18

标签: c# c++ unity3d dll dllimport

我创建了两个DLL,它们位于Assets / Plugins中。一个似乎工作正常,另一个给了我一个EntryPointNotFoundException,即使代码看起来与我完全相同。也许我在VisualStudio中错过了一些设置?我需要什么设置?

有效的那个看起来像这样:

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 ++标题

 #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;
 }

对于那些不起作用的人: 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 ++标题

#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;
 }

1 个答案:

答案 0 :(得分:1)

Dependency Walker显示没有导出的函数,但头文件中的导出函数看起来不错。似乎h文件未包含在cpp文件中。要检查这一点,请在函数定义中将__declspec(dllexport)放在cpp中。