I'm trying to debug a little test driver application written in C#. It opens up several instances of a test app we have. The test app connects to a server and when successfully connected, displays "REMOTE_CONNECTED" in a label. So the test driver is looking for that before attempting to feed in data to the test app.
Here's what the code looks like:
Console.Out.WriteLine("MAIN HANDLE IN GETCONN: " + Hwnd);
//Attempt to find if we have have connected to the remote server
IntPtr connHwnd = FindWindowEx(Hwnd, IntPtr.Zero, null, "REMOTE_CONNECTED");
That connHwnd always comes back a IntPtr.Zero and the Hwnd printed to the console is the handle I expect of the test app. The test driver sits in a loop for a while, repeatedly calling the above code until it finds that label. I can see on the screen that the label is displaying "REMOTE_CONNECTED" yet the function isn't finding it.
Furthermore, other folks have gotten this to work on XP (whereas I'm on Windows 7).
Finally, if I run this in Visual Studio and set some breakpoints, then it seems to work. So it doesn't seem like a logic flaw, but some sort of timing or contention issue.