2012-07-06 64 views
0

我想要一個簡單的程序,通過DLL訪問C函數轉換成C#程序在C#中,「無法找到名爲切入點」使用C DLL

class DllImportTest 
{ 
    [DllImport("TestApp.dll", EntryPoint = "main1")] 
    public static extern void main1(); 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     DllImportTest.main1() ; 
    } 

我已經通過代碼看到並且該函數的名稱完全正確。我也嘗試過使用Extern「C」,但是它將.C文件引發錯誤。 我已將.Dll放在C#可執行文件夾中。 有什麼我在這裏做錯了嗎?

+0

http://stackoverflow.com/questions/653178/unable-to-find-an-entry-point-named-function-in-dll-c-to -c-sharp-type-con – 2012-07-06 06:01:10

+0

如何從本機C客戶端調用相同的方法來測試它是否爲C#/ .NET問題或者庫無效。 – 2012-07-06 06:03:18

+0

我能夠創建一個相同的.lib並通過C控制檯應用程序,並運行它的工作文件。 – 2012-07-06 06:21:51

回答

1

找到了! 我不得不使用Extern「C」加上__declspec(dllexport)。我從來沒有一起使用過,謝謝你們

相關問題