我想从我的asp.net 3.5 Web应用程序链接到C ++ DLL并使用后面代码中的一些函数。如果我使用DllImport创建一个C#库链接到C ++ DLL,我可以将C#库链接到asp.net应用程序,它似乎工作。如何消除C#库并直接链接到C ++ DLL?
当我尝试在后面的C#代码中使用DllImport时,即使代码看起来与C#库中的代码相同,也是未定义的。
来自asp.net web应用程序的代码(不起作用,因为DllImport被突出显示为未定义)using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.InteropServices;
/// <summary>
/// Summary description for Chat
/// </summary>
public class Chat
{
public Chat()
{
[DllImport("ChatLib.dll")]
public static extern void DisplayHelloFromDLL();
}
}
答案 0 :(得分:1)
您可能需要在类级别上将DllImport
属性和方法声明放在侧构造函数中。
public class Chat
{
[DllImport("ChatLib.dll")]
public static extern void DisplayHelloFromDLL();
public Chat()
{
}
}