I got a crashdump where we’re debating whether a control was visible to the end user or not. Looking with !do I can’t see any explicit field that holds the true/false value matching up with the Visible property, which doesn’t surprise that much as we’re probably down in win32 teritory. Does anyone know how to deduce what Visible would have returned from the dump file?
thanks
Oskar
My initial thought was that this was just a question of looking up the right field, but actually it took a bit more digging. If you look at Control in Reflector, you’ll see that the Visible property calls GetVisibleCore, which checks an internal state field against the value 2 (which happens to be the constant STATE_VISIBLE).
So in order to find out if a control is visible, we need to locate the state field and do some bit manipulation.
If you have the address of the instance, you can do the following:
The output is something similar to this
Notice, that there are two state fields. I haven’t looked into why this is the case, but the one you want is the System.Int32. In my example it has a value of 17432589.
The code in GetState is as follows
so all you have to do from here is
(17432589 & 2) != 0and you’ll have the Visible state of the specific instance.Actually, you may have to go a step further. If the above returns false, you need to look up the parent and repeat the trick. For my simple example using a Form that was not necessary.