C++/CLI Wrapper - marshalling GUIDs

GUIDs, unique identifiers which can be assigned to items in C# and C++ are another set of variables which, despite sharing many characteristics, need to be marshalled between the C# implementation and C++ implementations when using the CLI wrapper.

Marshalling GUIDs between System.Guid and GUID

GUIDs are useful variables to pass between C# and C++ when working in both languages. They are unique in both, but can be passed across and assigned in each language so they can refer to the same portion of data. This makes it easy to match data up between the two languages, particularly if working between Dictionarys (C#) and Maps (C++). The GUID will identify the data uniquely, so you can guarantee you can call the equivalent data when you cross languages.

To marshal between them, you need two new functions in your C++/CLI code. One will convert a GUID to System.Guid, and the other will convert System.Guid to GUID. The code for both is shown below.

Converting GUID to System.Guid

Converting System.Guid to GUID

Marshalling GUIDs between System.Guid and GUID

Marshalling GUIDs between System.Guid and GUID


  1. By Yijiang Huang

  2. By FraserG

Leave a Reply

Your email address will not be published. Required fields are marked *