无法在 DLL“D:\jk\DynamicLibrary\Debug\MathFuncsDll”中找到名为“helloworld”的入口点。 说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.EntryPointNotFoundException: 无法在 DLL“D:\jk\DynamicLibrary\Debug\MathFuncsDll”中找到名为“helloworld”的入口点。源错误: 行 17: protected void Page_Load(object sender, EventArgs e)行 18: {行 19: string s = helloworld();行 20: Response.Write("<script>alert('"+s+"')</script>");行 21: }报的上面得错误我的代码如下:首先在.h文件里写如下代码定义方法:// MathFuncsDll.h#include <string> namespace MathFuncs{ class MyMathFuncs { public:static __declspec(dllexport) std::string helloworld(); // Returns a + b static __declspec(dllexport) double Add(double a, double b); // Returns a - b static __declspec(dllexport) double Subtract(double a, double b); // Returns a * b static __declspec(dllexport) double Multiply(double a, double b); // Returns a / b // Throws DivideByZeroException if b is 0 static __declspec(dllexport) double Divide(double a, double b); };}在.cpp文件里写如下代码实现方法:// MathFuncsDll.cpp#include "MathFuncsDll.h"#include <stdexcept>#include <string>using namespace std;namespace MathFuncs{std::string MyMathFuncs::helloworld(){return "helloworld";} double MyMathFuncs::Add(double a, double b) { return a + b; } double MyMathFuncs::Subtract(double a, double b) { return a - b; } double MyMathFuncs::Multiply(double a, double b) { return a * b; } double MyMathFuncs::Divide(double a, double b) { if (b == 0) { throw new invalid_argument("b cannot be zero!"); } return a / b; }}然后在web页面里写下面的代码调用:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Runtime.InteropServices;namespace MyWebDll{ public partial class _Default : System.Web.UI.Page { [DllImport(@"D:\jk\DynamicLibrary\Debug\MathFuncsDll")] public static extern string helloworld(); protected void Page_Load(object sender, EventArgs e) { string s = helloworld(); Response.Write("<script>alert('"+s+"')</script>"); } }}然后就报上面的错误。请高手指点。谢谢!没写过c++的,第一次用,有些东西表达不清楚还请见谅,谢谢啦!
- 3 回答
- 0 关注
- 455 浏览
添加回答
举报
0/150
提交
取消