Exposing STL containers over DLL boundaries is not a good idea, and generally not possible (see this answer for why, and this one about exposing a std::list over a dll boundary). I need to be able to pass data between DLL and EXE compiled with different (VC08/VC10+) compilers; this Q only deals with everything being the same.
What is the best way to expose them? Vectors are a bit different from lists in that the memory is guaranteed to be contiguous, so if I only need a const vector of doubles, can I merely supply begin and end pointers to the block to the function in the dll? The dll also needs to return some structure like an array of vectors.
I wondered about a struct containing begin and end pointers:
template <typename T>
struct vecWrapper<T> {
T* begin;
T* end;
}
// in the dll
int func(vecWrapper<double> numbers);
Would that be sensible? Presumably whatever is returned from the function would need a destructor (on the dll side) that destroys the things it points to.