dllにDoAllWorkというC++関数があります。その周りにac#ラッパーがあります。私はc#ラッパーでデリゲートを作成し、それをdllのc++関数へのコールバックとして渡します。
私のc#コードは次のとおりです。
public delegate int UpdateDelegate(int status);
public static int UpdateDelegate(int status)
{
return status;
}
[DllImport(_dllLocation)]
public static extern int DoAllWork( string param1, string param 2,... UpdateDelegate callbackproc);
}
私はc++ヘッダーファイルでDoAllWork関数を宣言し、次のようにcppファイルに実装しました。
.hファイル:
int DoAllWork(string param1, string param 2,... int (*statusfunction(int))
.cppファイル:
int DoAllWork(string param1, string param 2,... int (*statusfunction(int))
{
//do work;
}
次に、ExportAll.cppという3番目のcppファイルからc ++関数DoAllWorkをエクスポートします。コードは、次のとおりです。
EXPORT_FUNC Init(const char* path)
{
cppLibrary = new CPPLibrary();
return cppLibrary->Init(path);
}
EXPORT_FUNC DoAllWork(string param1, string param 2,...,
int(*statusfunction(int))
)
{
return cppLibrary->DoAllWork(string param1, string param 2,..., ??????);
}
私の問題は、最後のパラメーター(int(* statusfunction(int)))の引数を渡そうとしてもエラーが発生することです。
コールバック関数をパラメーターとして持つc++関数をエクスポートするときにパラメーターを渡す方法はありますか?
ありがとう