Hi-

I am trying to find a way to determine what data the user has selected from
a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
could be pointing to 1 of 3 possible structs. I have googled and searched
and I can't find a way to determine what type I'm dealing with.

Is this possible? There must be a method to figure this out.

Thanks for any suggestions!

-Steve

Re: determining what a ptr is pointing to by William

William
Tue May 11 13:54:32 CDT 2004

"sklett" <stevek@spamfree.net> wrote in message
news:OCtx5V4NEHA.808@tk2msftngp13.phx.gbl...
> I am trying to find a way to determine what data the user has selected
from
> a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
> could be pointing to 1 of 3 possible structs. I have googled and searched
> and I can't find a way to determine what type I'm dealing with.
>
> Is this possible? There must be a method to figure this out.

In general, it is not possible to know what a "naked" pointer references.

Sometimes this issue is addressed by defining a structure ( check the docs
for VARIANT ) which is comprised of a field used to contain the type
information and a union of all possible things in your world.

Regards,
Will




Re: determining what a ptr is pointing to by sklett

sklett
Tue May 11 14:32:48 CDT 2004

Thanks for the response!

I'm interested in this part of your response: "Better still, derive all the
structs from a common base struct which contains some way to identify
derived variants."
Would you mind going into a little more detail about this? It may be that
it is a common OOP term or suggestion, but I'm unclear.

I think you might be saying that I cast my pointer to the base struct, then
somehow from there I could tell which derived struct I'm dealing with. But
with OOP, when you are dealing with a base struct, you don't have access to
the derived structs. I'm not seeing how this all is connected.



"GuitarBill" <anonymous@discussions.microsoft.com> wrote in message
news:5B6B1AB1-690B-4BA2-8C83-028B55E07524@microsoft.com...
> If I understand you right, there's really no way to do that.
>
> One solution would be to put an identifying tag at the top of each struct.
Better still, derive all the structs from a common base struct which
contains some way to identify derived variants.



Re: determining what a ptr is pointing to by sklett

sklett
Tue May 11 14:34:00 CDT 2004

Thanks for the quick reply!
Reading on VARIANT right now, actually looking at it in oaidl.h and it looks
confusing ;)
I'll see what google can tell me and the docs as well.

Thanks again


"William DePalo [MVP VC++]" <willd.no.spam@mvps.org> wrote in message
news:%231fKkl4NEHA.2976@TK2MSFTNGP10.phx.gbl...
> "sklett" <stevek@spamfree.net> wrote in message
> news:OCtx5V4NEHA.808@tk2msftngp13.phx.gbl...
> > I am trying to find a way to determine what data the user has selected
> from
> > a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
> > could be pointing to 1 of 3 possible structs. I have googled and
searched
> > and I can't find a way to determine what type I'm dealing with.
> >
> > Is this possible? There must be a method to figure this out.
>
> In general, it is not possible to know what a "naked" pointer references.
>
> Sometimes this issue is addressed by defining a structure ( check the docs
> for VARIANT ) which is comprised of a field used to contain the type
> information and a union of all possible things in your world.
>
> Regards,
> Will
>
>
>



Re: determining what a ptr is pointing to by sklett

sklett
Tue May 11 16:25:31 CDT 2004

I ended up adding a byte member to each struct, then in the constructor
setting that to a value from an enum of possible types.
then I just check the first 2 bytes of the void*

works great.

Thanks guys for the suggestions!


"sklett" <stevek@spamfree.net> wrote in message
news:OCtx5V4NEHA.808@tk2msftngp13.phx.gbl...
> Hi-
>
> I am trying to find a way to determine what data the user has selected
from
> a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
> could be pointing to 1 of 3 possible structs. I have googled and searched
> and I can't find a way to determine what type I'm dealing with.
>
> Is this possible? There must be a method to figure this out.
>
> Thanks for any suggestions!
>
> -Steve
>
>



Re: determining what a ptr is pointing to by Simon

Simon
Wed May 12 11:45:01 CDT 2004

... or use dynamic_cast<> to attempt to convert from the base class (struct)
pointer to the derived class (struct) pointer, and check if it succeeds.

Requires RTTI though, IIRC.

"GuitarBill" <anonymous@discussions.microsoft.com> wrote in message
news:5B6B1AB1-690B-4BA2-8C83-028B55E07524@microsoft.com...
> If I understand you right, there's really no way to do that.
>
> One solution would be to put an identifying tag at the top of each struct.
Better still, derive all the structs from a common base struct which
contains some way to identify derived variants.



Re: determining what a ptr is pointing to by songie

songie
Wed May 12 14:39:15 CDT 2004

Redesign your structs so that they contain information in the first n bytes
relating to what type of struct they are perhaps??

"sklett" <stevek@spamfree.net> wrote in message
news:OCtx5V4NEHA.808@tk2msftngp13.phx.gbl...
> Hi-
>
> I am trying to find a way to determine what data the user has selected
from
> a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
> could be pointing to 1 of 3 possible structs. I have googled and searched
> and I can't find a way to determine what type I'm dealing with.
>
> Is this possible? There must be a method to figure this out.
>
> Thanks for any suggestions!
>
> -Steve
>
>



Re: determining what a ptr is pointing to by sklett

sklett
Wed May 12 15:13:57 CDT 2004

Thanks for the reply!

yeah, that is what I did. Works like a charm for my case.
I just have a byte and then I check that value again an enum of struct
types.

neat :)




"songie D" <songie@D.com> wrote in message
news:OuDYOjFOEHA.3420@TK2MSFTNGP11.phx.gbl...
> Redesign your structs so that they contain information in the first n
bytes
> relating to what type of struct they are perhaps??
>
> "sklett" <stevek@spamfree.net> wrote in message
> news:OCtx5V4NEHA.808@tk2msftngp13.phx.gbl...
> > Hi-
> >
> > I am trying to find a way to determine what data the user has selected
> from
> > a CTreeCtrl by retrieving the pointer stored in the ItemData. This ptr
> > could be pointing to 1 of 3 possible structs. I have googled and
searched
> > and I can't find a way to determine what type I'm dealing with.
> >
> > Is this possible? There must be a method to figure this out.
> >
> > Thanks for any suggestions!
> >
> > -Steve
> >
> >
>
>