.NETアプリケーションで使用するネイティブコンポーネントを開発するためにCプログラマを雇った。我々は概念的なAPIに合意した。私は彼の方法を2つの配列に渡し、配列を戻します。今日はコードがあります。ここにヘッダファイルがあります。本当の名前が隠されています。このことからC#でネイティブDLLを使用する
__declspec(dllexport) int NativeMethod(
struct params * config,
int c_input_a_rows,
struct input_a_row *input_a_rows,
int c_input_b_rows,
struct input_b_row *input_b_rows,
int c_count,
int *p_c_output_rows,
struct output_row * output_rows);
struct params
{
int a;
int b;
int c;
double d;
double e;
int f;
int g;
char h[1000];
};
struct input_a_row
{
int a;
int b;
double c;
};
struct input_b_row
{
int a;
int b;
int c;
int d;
int e;
double f;
double g;
};
struct output_row
{
int a;
int b;
int c;
int d;
int e;
int f;
int g;
double h;
double i;
double j;
};
私はP/Invoke Interop Assistantを使用して.NETコードを生成しました。私はDLLを開くことによって動作させることができませんでした。ファイルにアセンブリのマニフェストがないと訴えました。だから、私はSigImpl Translate Snippedにヘッダファイルを差し込みました。
[DllImport("the.dll", EntryPoint="NativeMethod")]
public static extern int NativeMethod(
ref params config,
int c_input_a_rows,
ref input_a_row input_a_rows,
int c_input_b_rows,
ref input_b_row input_b_rows,
int c_count,
ref int p_c_output_rows,
ref output_row output_rows);
また、すべてのものが期待どおりに作成されます。各クラスにはクラス属性があります。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
2つの質問。このコードは正しく生成されましたか?次に、私はそれをどのように使うのですか?署名には配列がありません。私はおそらく何とかポインタを使用する必要があることを知っているが、どのように?私はあなたが私のためにこれを解決するとは思っていませんが、低レベルのネイティブプログラミングでコースを取ることなくそれを理解する方法を理解する方法を教えてください。ありがとう!
C++名前のマングリングを無効にするには、extern "C"として宣言します。正確な構文についてはGoogleを参照してください。 –
また、リンカーに関数の名前を付ける方法を正確に伝えるもののC側で.defファイルを使用してください。 –