2011-06-08 61 views
0

我想存储指向本地类System::Object^和检索回来。存储和检索系统原生指针:对象^

class ABC; 

ABC * d = new ABC(); 

System::Object^ Tag; 
Tag = d; //This throws an error 

//in a different function 

ABC * c = safe_cast<ABC*>Tag; // this throws an error. 

哪种方法可以达到上述目的?

+0

你不能只保存本机的指针?为什么它必须是一个对象? – stijn 2011-06-08 06:35:37

+0

它的ListViewItem的标记属性。 – User234 2011-06-08 06:38:39

回答

0

使用IntPtr的结构,而不是对象。

 
IntPtr Tag(d); 

ABC * c = (ABC*)Tag.ToPointer(); 
+0

需要存储的ListViewItem的Tag属性的指针。类型是系统::对象^ – User234 2011-06-08 06:39:13

+0

@Ravikiran:阅读[拳击](http://msdn.microsoft.com/en-us/library/c53ss7ze.aspx)。 – ildjarn 2011-06-08 06:55:02

+0

@Ravikiran - 您可以使用gcnew InpPtr将其转化为对象^使用拳。 – 2011-06-08 06:59:05