Call a c++ dll with stl container from .net -
having following function in native dll:
double sum (std::vector<double> vals) { double s = 0.0; (size_t = 0; < vals.size(); i++) { s += vals[i] } return s; }
how can make callable .net (c#) ?
the problem is, there no pair vector<double>
.
is possible alter c++ side make call possible? (without giving std c++ feature, including ability call other c++ libraries )
it not possible , should not done: do not pass stl classes on dll interface
however create c-function called c#. parameters pass c-array of doubles , second parameter - length of array. wrapper function convert std::vector , call original function.
double sumwrapper(double* pointertodoublearray, unsigned int numberofelements) { //convert , call sum }
this c-function can called c++ using custom marshalling described here. option simple wrapper generator (swig) auto - generate c-wrapper function , c# function calls c++ function in dll.
the other option have add c++/cli wrapper function can called c# , converts .net array of doubles stl vector.
Comments
Post a Comment