// modify_ref_class_in_native_function_2.cpp
// compile with: /clr
using namespace System;
using namespace System::Runtime::InteropServices;
[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Unicode)]
ref class S {
public:
[MarshalAsAttribute(UnmanagedType::LPWStr)]
String ^ str;
[MarshalAsAttribute(UnmanagedType::ByValArray,
ArraySubType=UnmanagedType::I4, SizeConst=2)]
array<Int32> ^ intarr;
};
[DllImport("modify_ref_class_in_native_function.dll",
CharSet=CharSet::Unicode)]
int bar([In][Out] S ^ param);
int main() {
S ^ param = gcnew S;
param->str = "Hello";
param->intarr = gcnew array<Int32>(2);
param->intarr[0] = 100;
param->intarr[1] = 200;
bar(param); // Call to native function
Console::WriteLine("In managed: intarr: {0}, {1}",
param->intarr[0], param->intarr[1]);
}