I have an array of structures System::^ array
that is getting filled in a C# DLL
. Need to export that array of structures to C++ Dll
(in a function) and should use that exported array in my further C++ DLL
.
The Following is the C# code where the structure of Array gets filled (ReturningJSONArray
).
namespace JSON
{
public struct PJSONInfo
{
string sSetting;
double dMinVal;
double dMaxVal;
string sUnits;
}
public interface iCalFunction
{ PJSONInfo[] ReadJSON(); }
public class JSONReaderClass : iCalFunction
{
public PJSONInfo[] ReadJSON()
{
ILIST<PJSONInfo> JSONList = new List<PJSONInfo>();
..
..//(Fill the Ilist of PJSONInfo)
..
PJSONInfo[] ReturningJSONArray = JSONList.ToArray();
return ReturningJSONArray ;
}
}
}
(ReturningJSONArray is an array of structures that is been returned from the C# snippet.)
The Following is C++ code to which the C# function is linked as a DLL.
class CReadingClass
{
public :msclr::auto_gcroot<JSONReaderClass ^> pJSONClass;
}
int ReadJSONFromJSONReader()
{
CReadingClass* pReadClass;
pReadClass = new CReadingClass();
pReadClass ->pJSONClass =gcnew JSONReaderClass ();
System::Array^ JSONSetting = pReadClass -> pJSONClass -> ReadJSON();
//**JSONSetting** is a system::Array type of C# ,
return 1;
}
JSONSetting is a system::Array
type of C# , How do I convert that into something that is compatible with C++ (or equivalent Datatype).
I tried converting that into a vector of structure, but seems like there should be some conversions done (marshaling) can someone elaborate on this or is there any other workaround.