Managed type use in MFC App

S

Steven

Hi,

I have an enterprise application that was originally
written in VC 6.0 C++ as an MFC App. We
wanted to pull some new functionality into it
that is managed, so I now end up with a mixed
application of managed and unmanaged.
Using the MFC tree control I need to store
the managed type.

I put it in like this:

MyManagedType^ mt = gcnew MyMangedType();
m_MyTree.SetItemData(hTreeItemIndex, (DWORD_PTR)&mt);

Now I'm having trouble getting it out:

MyManagedType^ mt =
*(MyManagedType^*)m_DecoderTree.GetItemData(hItem);
//mt is not valid coming out.though it does compile and
//run without errors.

I even took some stabs at Marshal::ptrToStructure(), but
didn't think I needed to do that, but neither way is working.

Does this have to do with .Net moving it around in memory,
so it's not guaranteed to be in the same place?

How can I assign a managed type to the ItemData and retrieve
it?

Thanks!
 
S

Steven

I fixed it by putting it in an unmanaged struct with gcroot<>
and then put in and pulled out that unmanaged structure
that contained the managed resource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top