6

私は、c++ の関数を使用する c# の Windows フォーム アプリケーションを持っています。これは、C++ ラッパーを使用して行われました。ただし、この関数ではポインターを使用する必要があり、c# では文字列配列でポインターを使用することはできません。これを克服するために何ができるでしょうか?私はマーシャルの使用について読んだことがありますが、これがこのケースに適しているかどうかはわかりません。以下は C# コードです。

 int elements = 10;
string [] sentence = new string[elements];

unsafe
{
    fixed (string* psentence = &sentence[0])
    {
        CWrap.CWrap_Class1 contCp = new CWrap.CWrap_Class1(psentence, elements);
        contCp.getsum();
    }
}

C++ 関数宣言: funct::funct(string* sentence_array, int sentence_arraysize)

C++ ラッパー: CWrap::CWrap_Class1::CWrap_Class1(string *sentence_array, int sentence_arraysize) { pcc = new funct(sentence_array, sentence_arraysize); }

4

1 に答える 1