PDA

Click to See Complete Forum and Search --> : What am I pointing too?


Sam Finch
Jun 11th, 2000, 06:34 PM
I'm doing a set of dlls for use with VB, some of them return a pointer to a class so the VB user can refer to it later. The trouble is if the VB user doesn't pass in the right number or passes in a pointer to a class that's already destroyed the whole thing just crashes.

Is there a way of checkig if a particular address is a pointer to type of class?


thanks in adv

parksie
Jun 12th, 2000, 04:13 AM
not really, because all a pointer is is a memory location, and there's no other information available. if you were in C++ only, you could use run time type information which gives you full info on a class, including whether it's allocated or not. A possible way is to pass a type around:


Type MyClassWrapper
Pointer as Long
Allocated as Integer
End Type


So you use this and pass it to your C++ functions, and if any of them deallocate it, they set the Allocated member to 0, and everything checks this before doing anything.