2016-11-07 139 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; 
    } 
相關問題