Validating a Win32 Window Handle


Given a handle of type HWND is it possible to confirm that the handle represents a real window?


There is a function IsWindow which does exactly what you asked for.

BOOL isRealHandle = IsWindow(unknwodnHandle);

Look at this link for more information.

By : Serge

What you're asking is whether accessing a field in a method multiple times atomic -- to which the answer is no.

In the example above, the initialise routine is faulty as it may result in multiple initialization. You would need to check the s_Initialized flag inside the lock as well as outside, to prevent a race condition in which multiple threads read the s_Initialized flag before any of them actually does the initialisation code. E.g.,

private static void Initialize()
    if (s_Initialized)

        if (s_Initialized)
        s_Provider = new MembershipProvider ( ... )
        s_Initialized = true;
By : olliej

I think you're asking if s_Initialized could be in an unstable state when read outside the lock. The short answer is no. A simple assignment/read will boil down to a single assembly instruction which is atomic on every processor I can think of.

I'm not sure what the case is for assignment to 64 bit variables, it depends on the processor, I would assume that it is not atomic but it probably is on modern 32 bit processors and certainly on all 64 bit processors. Assignment of complex value types will not be atomic.

This video can help you solving your question :)
By: admin