I have a Windows Forms application in C # that uses a function in C ++. This was done using the C ++ shell. However, the function requires the use of pointers, and C # does not allow the use of pointers with string arrays. What can be done to overcome this? I read about using a marshal, but I'm not sure if this is suitable for this case, and if so, how it should be integrated with my code. Below is the C # code:
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 ++ function description: funct::funct(string* sentence_array, int sentence_arraysize)
C ++ wrapper: CWrap::CWrap_Class1::CWrap_Class1(string *sentence_array, int sentence_arraysize) { pcc = new funct(sentence_array, sentence_arraysize); } CWrap::CWrap_Class1::CWrap_Class1(string *sentence_array, int sentence_arraysize) { pcc = new funct(sentence_array, sentence_arraysize); }
source share