You don't say what is 0. However you're not checking the return value from FindWindow()/FindWindowEx() which are NULL if not found.