Resource Page Description An extension (template specialization) to marshal_as<> library of Visual C++ 2008, to convert Unicode string arrays between managed (CLR) and native (STL/C++) code.
This project shows how to specialize marshal_as<> template library of Visual Studio 2008, to allow marshaling of list of (Unicode) strings between managed and native worlds. The main file is the header: marshal_stringarray.h This file contains the marshal_as aforementioned template specialization, and it should be included in projects that requires this kind of marshaling. There are several options to store list of strings in C++. For this project, I chose to use std :: wstring as Unicode (UTF-16) string class, and std :: vector as container of strings. Both classes ( std :: wstring and std :: vector) are from STL. Using this marshaling is as simple as this: // Marshal from STL string array to CLR string array ClrStringArray^ clrNames = marshal_as< ClrStringArray^ >( names ); // Marshal from CLR string array to STL string array StlStringArray stlNames = marshal_as< StlStringArray >( clrNames ); Extending and "crafting" the code to make it working with similar classes (like CStringW) should be easy enough. Giovanni Dicanio
|