2013-10-04 111 views
1

時,DllImport在asp.net代碼後面沒有定義,但我想從我的asp.net 3.5 web應用程序鏈接到C++ dll,並使用後面代碼中的一些功能。如果我使用DllImport創建一個C#庫鏈接到C++ DLL,我可以將C#庫鏈接到asp.net應用程序,它似乎工作。如何消除C#庫並直接鏈接到C++ dll?即使在包含System.Runtime.InteropServices

當我嘗試在後面的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(); 
    } 
} 

回答

1

你可能需要把DllImport屬性和方法聲明瞭側構造上一流水平。

public class Chat 
{ 
    [DllImport("ChatLib.dll")] 
    public static extern void DisplayHelloFromDLL(); 
    public Chat() 
    { 

    }   
} 
+0

哈哈好的謝謝。我盯着這段代碼太久了,沒有看到。如果答案很簡單,我想這很好。 :) – user2684001

相關問題