無(wú)法在 DLL“D:\jk\DynamicLibrary\Debug\MathFuncsDll”中找到名為“helloworld”的入口點(diǎn)。? 說(shuō)明: 執(zhí)行當(dāng)前 Web 請(qǐng)求期間,出現(xiàn)未經(jīng)處理的異常。請(qǐng)檢查堆棧跟蹤信息,以了解有關(guān)該錯(cuò)誤以及代碼中導(dǎo)致錯(cuò)誤的出處的詳細(xì)信息。? 異常詳細(xì)信息: System.EntryPointNotFoundException: 無(wú)法在 DLL“D:\jk\DynamicLibrary\Debug\MathFuncsDll”中找到名為“helloworld”的入口點(diǎn)。源錯(cuò)誤:? 行 17: protected void Page_Load(object sender, EventArgs e)行 18: {行 19: string s = helloworld();行 20: Response.Write("<script>alert('"+s+"')</script>");行 21: }報(bào)的上面得錯(cuò)誤我的代碼如下:首先在.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文件里寫如下代碼實(shí)現(xiàn)方法:// 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頁(yè)面里寫下面的代碼調(diào)用: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>");? }? }}然后就報(bào)上面的錯(cuò)誤。請(qǐng)高手指點(diǎn)。謝謝!沒(méi)寫過(guò)c++的,第一次用,有些東西表達(dá)不清楚還請(qǐng)見諒,謝謝啦!
- 3 回答
- 0 關(guān)注
- 478 瀏覽
添加回答
舉報(bào)
0/150
提交
取消