【问题标题】:EntryPointNotFoundException in one DLL while seems fine in another一个 DLL 中的 EntryPointNotFoundException 而在另一个 DLL 中似乎很好
【发布时间】:2016-08-17 20:04:17
【问题描述】:

我创建了两个 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;
 }

【问题讨论】:

    标签: c# c++ unity3d dll dllimport


    【解决方案1】:

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

    【讨论】:

    • 这是一个非常好的工具,谢谢。当我检查正在运行的那个时,所有功能都显示为未损坏。当我检查不工作的那个时,根本没有显示任何功能。
    • @mBajema 好兆头,请检查您是否为示例平台编译了两个 dll - x86 或 x64
    • 我在配置管理器中将它们都设置为 Release Configuration Platform x64。
    • @mBajema 重新检查链接器 -> 附加 -> 目标机器中的第二个 dll 的链接器选项。对于 x64,应该有 MachineX64 值。
    • 目标机器对两者都说 MachineX64 (/MACHINE:X64)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    相关资源
    最近更新 更多