This short guide explains how arrays of IEC strings are passed between managed C# code and native C++ using the eCLR. It follows the same patterns as for numeric arrays and structs, with string-specific handling in native code.
- Arrays are passed as pointers and must be declared as [InOut] to allow native code to read and modify them.
- A [Native] method wrapper exposes the operation to managed code.
StringArrayFB1NativeMethods-cli.cpp
- Methods are exposed to managed code via the PInvoke prefix.
- String elements are accessed through the array’s Anchor and copied using IEC string APIs.
- A [Native] function block can implement its logic entirely in native code; only explicitly marked [Managed] members run in C#.
- Arrays must be passed as pointers and marked [InOut] to enable native read/write access.
- Always null-check pointers before use in native code.
- Use GetLowerBound/UpperBound to determine array size.
- For IEC strings (e.g. IecString200), copy contents with Assign(Begin(), GetLength()) rather than copying raw memory.
- The [Native] attribute on classes/methods and the PInvoke prefix in C++ define the managed–native boundary.