2012-02-22 124 views
4

我從我試圖參數發送到C++功能的C#應用​​程序。不過,我收到錯誤(在主題中提到)無法找到入口點DLL

C#應用程序:

static class SegmentationFunctions 
{ 
[DllImport("MyApplication.dll", EntryPoint = "fnmain", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] 
     public static extern int fnmain(string search); 
    } 
} 

public partial class MainWindow:Window 
{ 
public MainWindow() 
{ 
InitializeComponent(); 

string search = "test string here"; 
int scommand = SegmentationFunctions.fnmain(search); 
} 

C++ file.h

extern "C" QUERYSEGMENTATION_API int fnmain(char query[MAX_Q_LEN]); 

C++文件的.cpp

extern "C" QUERYSEGMENTATION_API int fnmain(char searchc[MAX_LEN_Q]) 
{ 

do something... 

} 
+1

QUERYSEGMENTATION_API *明確*在您的C++項目中定義爲__declspec(dllexport),並且您可以在Dependency Walker中打開MyApplication.dll時看到導出的函數(depends.exe是Visual Studio工具,以防您不確定)? – adelphus 2012-02-22 10:21:15

回答

5

Dependency Walker可以顯示哪些函數可以有效地從DLL中導出。您將可以看到,如果你的fnmain有可言,或者是_fnmain代替,或在其名稱中的C++裝飾。

0

注意,默認情況下Visual Studio將您的母語不是輸出複製到同一文件夾作爲您的管理輸出。

原生輸出手動複製到自選build文件夾,然後再試一次 - 如果,那麼你需要改變C++構建設置把目標文件夾與您的託管應用程序文件夾,那是你的問題。

你的代碼是正確的 - 只要QUERYSEGMENTATION_API宏正確定義和你的DLL實際上是在建的「MyApplication.dll」

我想手動運行從文件系統中可執行文件 - 在確認最新的exe和dll都在同一個文件夾中,如果失敗,運行depends.exe來弄清楚。

+0

我已經有了用於獲取C#項目中最新dll的後生成集。 – Cipher 2012-02-22 10:44:00

相關問題