2016-11-07 137 views
-2

我定义为C#代码的对象如下:如何将C#类对象传递给C++非托管代码?

class CSObject 
{ 
    int length; 
    int width; 
    IList<SubItem> Items; 
    bool OnSale;  
    ItemType type; //ItemType is an enum 
} 

Class SubItem 
{ 
    object AssociatedValue; 
    List<Range> Highlight; // Range is another class represents a pair (0, 4) 
    string Name; 
    IList<SubItem> Items; 
    string Title; 

} 

现在,我们如何把这个在C++代码的方法?

  1. 我是否需要在C++端创建类似的类并发送这些数据并在那里进行derseialize?
  2. 我不需要修改C++端的对象,只需要遍历它。
+0

你可以找到答案[这里](https://msdn.microsoft.com/ EN-US /库/ eshywdt7(v = vs.110)的.aspx)。 – dymanoid

回答

-2

我不知道这能帮助你,但我以前使用的一些这样的事很花时间

public struct AccountInfo 
    { 
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 
    public byte[] ExpirationDate; 
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)] 
    public string CustomerId; 
    } 
相关问题