[英]Unhandled Exception: System.EntryPointNotFoundException in DLL
This is below C++ DLL source file. 这是在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;
}
}
similary header file 相似头文件
//CalSimpleInterest.h
namespace simpleInt
{
class calculateInterest
{
public:
static __declspec(dllexport) double CalSimplInterest(double Principal, double Rate, double Time);
};
}
I have compiled and created CalSimpleInterest.dll . 我已经编译并创建了CalSimpleInterest.dll。 Now I want to use CalSimplInterest() function in C#.
现在,我想在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();
}
}
}
It is compiling successfully. 它编译成功。 But it is showing following Error at run time.
但是它在运行时显示以下错误。
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
As I am naive to C#, please help me to resolve this issue. 由于我不熟悉C#,请帮助我解决此问题。 Thanks in Advance.
提前致谢。
i'm not sure but i wonder if you try to Export a class method. 我不确定,但我想知道您是否尝试导出类方法。 Just try to write your method in ac or c++ code file and Export it in the Header file.
只需尝试在ac或c ++代码文件中编写您的方法,然后将其导出到Header文件中即可。 Then try it again.
然后再试一次。 It's just a try...
只是尝试...
Furthermore u can check the compiler options under C/C++ -> Advanced -> Calling Convention. 此外,您可以在C / C ++->高级->调用约定下检查编译器选项。 Make sure the Option is __cdecl (/Gd).
确保选项是__cdecl(/ Gd)。 If it is __fastcall or __stdcall, WINAPI or whatever u have to use this calling convention or switch it to __cdecl (/Gd).
如果是__fastcall或__stdcall,则WINAPI或您必须使用此调用约定或将其切换到__cdecl(/ Gd)的任何对象。
U can use Dumpbin as described or a tool like DependencyWalker/depends.exe with a graphical user Interface. U可以使用描述的Dumpbin或带有图形用户界面的工具DependencyWalker / depends.exe。
Dumpbin.exe /EXPORTS "c:\\user\\x\\code\\bestcodeever\\myDllThatExportsSomeSmartThings.dll" works for me... Dumpbin.exe / EXPORTS“ c:\\ user \\ x \\ code \\ bestcodeever \\ myDllThatExportsSomeSmartThings.dll”对我有用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.