These classes are located in \Samples\Com\IMarshal\Sample\Util.
Note To use this sample, it is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.
Description
Technologies Demonstrated
The Sample.util package of classes was created to simplify the creation of arrays of C structure objects, and take care of the marshaling of the arrays between Java and C. This package is required, as an array of objects in Java is essentially a pointer to a list of pointers, whereas in C an array of structures is a pointer to the first byte of the first structure, and all structures are sequentially ordered in memory.
To create the equivalent structure in Java, the Sample.util package allocates continuous memory and maps the structures to that memory. It uses a weak reference onto the allocated array to track when the array has died and the memory can be freed. The CStructArray object, which is created using the static method sample.util.StructArray.toCStructArray, passes the array of structures through a J/Direct call. This is required to propagate any non-primitive fields (such as strings, com.ms.com._Guid, or com.ms.com.Iunknown) between Java and C. If the structure array is embedded within a structure, the propagation between Java and C can be accomplished using a Custom Marshaler specified with the dll.structmap directive for that field.