首页 新闻 会员 周边

关于c#调用c#DLL问题

0
悬赏园豆:50 [已关闭问题]
1 c#写的DLL
2  using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6
7 namespace SDKDAL
8 {
9 public static class demo
10 {
11 public static string GetText()
12 {
13 return "测试";
14 }
15 }
16 }
17
18
19 下面是在asp.net调用(c#语言)
20 using System;
21 using System.Configuration;
22 using System.Data;
23 using System.Linq;
24 using System.Web;
25 using System.Web.Security;
26 using System.Web.UI;
27 using System.Web.UI.HtmlControls;
28 using System.Web.UI.WebControls;
29 using System.Web.UI.WebControls.WebParts;
30 using System.Xml.Linq;
31 using System.Runtime.InteropServices;
32
33 public partial class _Default : System.Web.UI.Page
34 {
35 protected void Page_Load(object sender, EventArgs e)
36 {
37 if(!IsPostBack)
38 {
39 string str=GetText(); //调用自己写的就报错,运行时报无法在 DLL“SDKDAL.dll”中找到名为“GetText”的入口点。
40
41
42 //调用系统的可以
43 string myString="请选择!";
44 MessageBoxTEST(0, myString, "是否取消呢?", 3);
45
46 }
47
48 }
49
50 [DllImport("User32.dll", EntryPoint = "MessageBox")]
51 public static extern int MessageBoxTEST(int h, string m, string c, int type);
52
53
54 [DllImport("SDKDAL.dll")]
55 public static extern string GetText();
56 }
57
58

 

txsun的主页 txsun | 初学一级 | 园豆:100
提问于:2010-05-16 22:09
< >
分享
其他回答(5)
0
 2  using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6
7 namespace SDKDAL
8 {
9 public static class GetText
10 {
11 public static string GetText()
12 {
13 return "测试";
14 }
15 }
16 }
这样试一下
千羽 | 园豆:666 (小虾三级) | 2010-05-16 23:41
这样写编译都通不过的啊。
支持(0) 反对(0) txsun | 园豆:100 (初学一级) | 2010-05-16 23:48
0

引用即可

不能引用编译时绑定,则可运行时加载程序集,反射调用

DllImport 引入的是导出函数

钧梓昊逑 | 园豆:945 (小虾三级) | 2010-05-16 23:51
0

为什么要这么用呢,直接 引用Dll。

然后在使用的页面using命名空间,直接GetText就可以用了,还费这劲干什么啊。

邢少 | 园豆:10926 (专家六级) | 2010-05-17 10:39
0

.net 编写的 dll 在 .net 中调用不能使用 DllImport 方式,

你只能直接引用 dll.或者用 Assembly.Load 外加 Reflecte.

Launcher | 园豆:45045 (高人七级) | 2010-05-17 14:45
0

间接引用用反射。

winzheng | 园豆:8797 (大侠五级) | 2010-05-19 13:53
0

直接添加dll的引用,然后引用命名空间不就可以了。为什么要用DllImport引入呢

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2010-05-19 14:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册