Jump to content
  • Advertisement
Sign in to follow this  
jonboy

[.net] Passing unmanaged structures to managed code (C++)

This topic is 5050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have some structures which are not managed, and I use them in a managed class. Much like this... typedef struct StuffTag { int nA; int nB; } Stuff; __gc class CClass { public: void AFunction(Stuff sIn) { // do something } void BFunction() { /* Will report an error saying that cannont convert m_sStuff into an non __gc Stuff) */ AFunction(m_sStuff); } Stuff m_sStuff; }; The thing is that if I try and pass the m_sStuff as a parameter I get an error saying unable to convert from __gc to non __gc. Along a similar line if I had a method inside CClass void DoSomething() { Stuff sNew = m_sStuff; } Would report an error because it says m_sStuff cannot be converted into sNew, because sNew is non __gc. You can fix this with Stuff __pin *spStuff = &m_sStuff; Stuff sNew = *spStuff; Yuk. I just can't believe thats the way I'm supposed to do things! So how should I be passing around by non __gc structures in managed code? Thanks! Jonathan

Share this post


Link to post
Share on other sites
Advertisement
Try making m_sStuff a pointer. I'm not 100% certain, but I don't think that a managed C++ class can have a member that is an unmanaged type.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!