Sign in to follow this  

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

This topic is 4838 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
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

This topic is 4838 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this