EntryPointNotFoundException在一个DLL中,而在另一个DLL中似乎很好

本文关键字:DLL 另一个 很好 一个 EntryPointNotFoundException | 更新日期: 2023-09-27 18:02:54

我创建了两个dll,它们位于资产/插件中。一个似乎工作得很好,另一个给了我一个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;
 }

EntryPointNotFoundException在一个DLL中,而在另一个DLL中似乎很好

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