Hello , thanks for your reply. Have figured it out. It should be like this ->
C++
std::vector<std::string> ColumnNames;
std::vector<std::string> ColumnValues;
char ** arrnames = new char*[ColumnNames.size()];
for (size_t i = 0; i < ColumnNames.size(); i++) {
arrnames* = new char[ColumnNames*.size() + 1];
strcpy(arrnames*, ColumnNames*.c_str());
}
char ** arrvalues = new char*[ColumnValues.size()];
for (size_t i = 0; i < ColumnValues.size(); i++) {
arrvalues* = new char[ColumnValues*.size() + 1];
strcpy(arrvalues*, ColumnValues*.c_str());
}
bool result = DLLFuncPtr(length, tablename, arrnames, arrvalues);
C#
[DllExport("InsertData", CallingConvention = CallingConvention.Cdecl)]
static public bool InsertData(int columncount , String TableName, [In , MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 0)]String] ColumnNames , [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 0)]String] Values)
{
//Body
}
It actually shouldn’t be like this, because you forgot to delete every single array and now have multiple memory leaks in your program.
Use std::vector<char*> or TArray<char*> instead. TArray has GetData() method for situations like this.