【问题标题】:Unhandled Exception: System.EntryPointNotFoundException in DLL未处理的异常:DLL 中的 System.EntryPointNotFoundException
【发布时间】:2013-06-19 15:33:41
【问题描述】:

这是下面的 C++ DLL 源文件。

//SimpleInterest.CPP
#include <iostream>
using namespace std;
#include "CalSimpleInterest.h"

namespace simpleInt
{
    // total interest 
    double calculateInterest:: CalSimplInterest(double Principal, double Rate, double Time)
    {
        double interest = 0.0;
        interest = (Principal * Time * Rate) / 100;
        return interest;
    }
}

类似的头文件

//CalSimpleInterest.h
namespace simpleInt
{
    class calculateInterest
    {
        public:
        static __declspec(dllexport) double CalSimplInterest(double Principal, double Rate, double Time);
    };
}

我已经编译并创建了 CalSimpleInterest.dll 。现在我想在 C# 中使用 CalSimplInterest() 函数。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        // Set the library path
        const string dllFilePath =
        "C:\\Users\\ggirgup\\Documents\\Visual Studio 2012\\Projects\\CalSimpleInterest\\Debug\\CalSimpleInterest.dll";


        // This is the function we import from the C++ library.
        //[DllImport(dllFilePath)]
        [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)]
        public static extern double CalSimplInterest(double Principal, double Rate, double Time);

        [DllImport(dllFilePath, CallingConvention = CallingConvention.Cdecl)]
        public static extern double TotalPayback(double Principal, double Rate, double Time);

        static void Main(string[] args)
        {
            Console.WriteLine(
                "Call C++ function in C# ");

            // Call C++ which calls C#
            CalSimplInterest(1000,1,2);
           // TotalPayback(1000, 1, 2);
            // Stop the console until user's pressing Enter
            Console.ReadLine();
        }


    }
}

编译成功。但它在运行时显示以下错误。

Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry  point named 'CalSimplInterest' in DLL 'C:\Users\ggirgup\Documents\Visual
Studio
 2012\Projects\CalSimpleInterest\Debug\CalSimpleInterest.dll'.
   at ConsoleApplication1.Program.CalSimplInterest(Double Principal, Double Rate , Double Time)
   at ConsoleApplication1.Program.Main(String[] args) in c:\Users\ggirgup\Docume nts\Visual Studio 2012\Projects\CsharpCallingCPPDLL\CsharpCallingCPPDLL\Program.
cs:line 46

由于我对 C# 很幼稚,请帮我解决这个问题。 提前致谢。

【问题讨论】:

  • this question 对您有帮助吗?
  • 它只是没有您认为的名称。在你的 DLL 上使用 dumpbin.exe /exports 来查看真实名称。
  • 我试图将 dumpbin.exe 用于 CalSimpleInterest.dll。但我看不到任何细节。那么如何使用dumpbin.exe /exports?

标签: c# c++ dll entrypointnotfoundexcept


【解决方案1】:

我不确定,但我想知道您是否尝试导出类方法。只需尝试在 c 或 c++ 代码文件中编写您的方法并将其导出到头文件中。然后再试一次。这只是一个尝试......

此外,您可以检查 C/C++ -> 高级 -> 调用约定下的编译器选项。确保选项是 __cdecl (/Gd)。如果是 __fastcall 或 __stdcall,WINAPI 或任何你必须使用此调用约定或将其切换到 __cdecl (/Gd)。

您可以使用描述的 Dumpbin 或具有图形用户界面的 DependencyWalker/depends.exe 等工具。

Dumpbin.exe /EXPORTS "c:\user\x\code\bestcodeever\myDllThatExportsSomeSmartThings.dll" 适合我...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 2013-03-18
    • 2017-04-22
    • 2012-12-03
    相关资源
    最近更新 更多