From: Steven on
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!


From: Steven on
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.


"Steven" <sedison(a)protronix_nospam_.com> wrote in message
news:OxR2wWO0KHA.260(a)TK2MSFTNGP05.phx.gbl...
> 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!
>