This is not a problem. The class is the same but the handles are always different in different instances. In your example, if it returns a successfully found handle, its value will the same as the value of
TextBox.Handle
(inherited from
Control
) of one of the instances of your text boxes. In this way, you made a round trip. See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[
^].
In practice, this is never needed as you always have this handle through this property.
I don't know why would you try to find it using Windows API, perhaps because you did not know about this property.
A word of warning: the use of handles and Windows API (via P/Invoke) is not needed in correct .NET UI development; most of the problems can be solved using pure .NET libraries. Moreover, using handles would break compatibility with other platforms. Did you know that accurately written Forms application can run on many platforms
without recompilation, not just Windows? This can be done using Mono (
http://en.wikipedia.org/wiki/Mono_%28software%29[
^]). Using handles (HWND) or P/Invoke will break such compatibility.
Too bad you did not share your ultimate goal. If you did, chances are, we would give you a good advice on how to do things using pure .NET libraries.
—SA