Question

We have a legacy C++ program (standard C++ not managed) with many methods. Most use parameters of char and int. However, one has the following method signature:

Convert(CDataSet &DataSet, CValue &Var, char *pOutput, int &nParser)

We need to call that method from C#. We have an existing Managed C++ class that can call the unmanaged methods that need char and int without problems. But we are at wits end on how to call a C++ method from C# when it needs to have a dataset passed to it. Some have told us that is impossible to do so. Is that true?

If we can't pass a dataset is it possible to pass an object and then have managed class cast it as dataset to pass to unmanaged class?

Was it helpful?

Solution

In your managed C++ wrapper lib accept System.Data.DataSet for example and convert it's data to CDataSet and call unmanaged code. On return convert the updates back (if needed).

UPD: by "convert" I mean create a new instance of CDataSet class inside your wrapper method, populate it's data from managed object and then call unmanaged function. When it returns transfer data back to original managed object if necessary and return.

If you need to manage the updates to the object between calls or accross process boundaries (i.e. other function calls result in updates to this object even when object is not passed) than create a wrapper around unmanaged object and provide managed interface that would let you manipulate the object at required level.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top