However, for C++ programmers, instead of working at the C-interface level, it’s more convenient to use higher-level C++ classes, such as the Active Template Library (ATL) CComSafeArray. For further details on the SAFEARRAY C data structure and some of its native C-interface APIs, see the online companion piece to this article, “Introducing the SAFEARRAY Data Structure” ( /magazine/mt778923). There are also C-interface Windows APIs for manipulating safe arrays, such as SafeArra圜reate and SafeArrayDestroy for creation and destruction, and other functions to lock a safe array instance and safely access its data. A safe array is usually handled in code via a pointer to its SAFEARRAY descriptor, that is, SAFEARRAY*. Basically, the SAFEARRAY data structure describes a particular instance of a safe array, specifying attributes such as its number of dimensions and a pointer to the actual safe array’s data. The Windows programming platform offers a convenient ready-to-use data structure that can be used for that purpose: the SAFEARRAY, whose definition can be found on the Windows Dev Center ( bit.ly/2fLXY6K). Passing that data across module boundaries isn’t trivial and requires the use of well-designed and well-crafted data structures.
Or, you might have a Windows service written in C++ that interacts with other low-level modules and returns arrays of strings that you want to consume in GUI clients written in C#, or in a scripting language. For example, you might have some C++ components that interact with some hardware and produce an array of data, like an array of bytes representing the pixels of an image read from an input device, or an array of floating point numbers representing measurements read from a sensor.
Often, you want to exchange some data in the form of arrays between those components.