I'm writing a CLI/C++ wrapper around a native C++ dll which can not be changed. One of the functions of the native DLL returns a vector of unmanaged objects. What would be the best way to wrap this vector in my CLI wrapper? The CLI wrapper is going to be used by a C# application.
class __declspec(dllexport) Instrument
{
public:
Instrument();
~Instrument();
string _type;
unsigned int _depth;
}
The native DLL has the function getInstruments() which is what I'm trying to wrap
class __declspec(dllexport) InstrumentList
{
InstrumentList();
~InstrumentList();
vector<Instrument*> getInstruments();
}
So I need to wrap the instrument class in a managed class and wrap InstrumentList class in a managed class. I have the Instrument class wrapped, but need to convert the vector returned by getInstruments() into something equivalent that the CLI wrapper for InstrumentList can return.
Instrument::_type
is accessed or once whenInstrumentList::getInstruments()
is called? – ildjarnstd::vector<>
orstd::string
are, so that wouldn't be very useful. – ildjarnstd::vector
isn't guaranteed to have compatible definitions in different DLLs, so exporting it across DLL boundaries is a very bad idea. Ditto forstd::string
. Putting the native code and managed wrapper into a single DLL would be fine, the C++ details are hidden within a single DLL, and .NET objects are designed to have standard binary interfaces that can cross DLL boundaries. – Ben Voigt