在asp.net里的C#后台调用dll时出现using缺失问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 21:44:46
我在aspx.cs文件中写入如下代码:
using System.Runtime.InteropServices;
class test
{
[DLLImport("DLLtest")]
private extern static int ttt();
}
public partial class user_TreeView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton5_Click(object sender, EventArgs e)
{
Label1.Text = test.test().toString();
}

}
编译运行时出现以下错误:
错误 1 找不到类型或命名空间名称“DLLImport”(是否缺少 using 指令或程序集引用?) D:\inetpub\MuiscPlatform\user\TreeView.aspx.cs 44 6 D:\inetpub\MuiscPlatform\
错误 2 找不到类型或命名空间名称“DLLImportAttribute”(是否缺少 using 指令或程序集引用?) D:\inetpub\MuiscPlatform\user\TreeView.aspx.cs 44 6 D:\inetpub\MuiscPlatform\

请问大侠有什么方法解决呢?

[DLLImport("DLLtest")]
错误是大小写不正确造成的。
另外注意DLLtest---》DLLtest.dll
做程序一定要认真。
不然以后你做出的东西,一点一个错误,谁还用?

using System;
using System.Runtime.InteropServices;
class MainApp
{
//通过DllImport引用user32.dll类。MessageBox来自于user32.dll类
[DllImport("user32.dll", EntryPoint="MessageBox")]
public static extern int MessageBox(int hWnd, String strMessage, String strCaption, uint uiType);
public static void Main()
{
MessageBox( 0, "您好,这是 PInvoke!", ".net", 0 );
}

[DLLImport("DLLtest")]
是否该为[DLLImport("DLLtest.dll")]

fd

using System;
using System.Runtime.InteropServices;