我無法從我的c#代碼中將字符串數組傳遞給函數從我的C++ dylib。C#:將字符串數組傳遞給C++ dll/dylib
C#代碼:
[DllImport("array2d.dylib", EntryPoint = "process_array", CallingConvention = CallingConvention.Cdecl)]
public static extern int process_array(String[] a, int b);
static void Main(string[] args)
{
String[] list = new String[] { "Abc" , "def", "ghi", "jkl"};
int josh = process_array(list, 2);
}
我的C++代碼:
#include <string>
#include <iostream>
int process_array(char** array, int rows)
{
std::string s1 ("Array : [");
for (int i = 0; i < 6; ++i){
s1.append(array[i]);
s1.append(", ");
}
s1.append("] \n");
return 1;
}
int main()
{
}
而且我已經得到的錯誤是:
未處理的異常:System.EntryPointNotFoundException:無法找到一個條目在DLL'array2d.dylib'中命名爲'process_array'。 at JoshServer.Program.process_array(String [] a,Int32 b)
任何幫助表示讚賞,謝謝。
您的cpp文件是否導出任何功能?必須有一些關鍵字,如dllexport。閱讀有關在cpp中創建dll的信息。 –