开发者

Store and retrieve native pointer from System::Object^

开发者 https://www.devze.com 2023-03-11 22:30 出处:网络
I want to store a pointer to a native class in System::Object^ and retrieve it back. class ABC; ABC * d = new ABC();

I want to store a pointer to a native class in System::Object^ and retrieve it back.

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.

Wh开发者_如何学JAVAich is the proper way to achieve the above behavior?


Use IntPtr structure instead of Object.

IntPtr Tag(d);

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号