www.fruitfruit.com said:
Memory allocated by a DLL shall also be freed by itself.
If you return a vector from that DLL, you violated above rules.
In fact, you can do that if you ensure that all of the following is true:
* The DLL and the app are compiled with the same compiler and linker
settings, with the exact same version of the compiler and linker, and
using the exact same STL version
AND
* All modules are linked against the dynamic version of the runtime library
In this case you can allocate memory in a DLL and delete it in the main
app, and vice versa, because the memory allocator itself is in the same
DLL (the Microsoft runtime library). You must ship the correct Microsoft
DLLs with your app as dependencies.
If you can't meet all of those conditions, you're not able to use
std::vector in the exported DLL function declarations (whether a return
value or an input argument, it doesn't matter).
Also note that returning a vector from a function returns it by value,
which means a copy of the vector is created. It's more efficient to pass
the vector by reference in one of the input arguments:
void f(vector<int>& output);
Tom