4

Does anybody know what would cause the FindWindow function to return the error:

ALREADY_EXISTS error (183)

I could understand a FILE_NOT_FOUND (2), but why would it return a 183?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
windev
  • 49
  • 2
  • 4
    Are you sure that `FindWindow` is the one returning that error? Can you post some code to show us what you're doing? – Jim Mischel Jul 08 '11 at 23:44
  • 3
    FindWindow would never result in ALREADY_EXISTS. Nor will it result in a FILE_NOT_FOUND for that matter. Are you sure you are looking up a, euhmmm..., window? Aren't you looking for a file? – NGLN Jul 09 '11 at 17:14
  • 1
    Can you share some code? Are you calling GetLastError after FindWindow, or taking to returned value to be error-code? – Ajay Jul 11 '11 at 15:31
  • 1
    GetLastError returns the error value from the last winapi function that failed not from the last function that was called. So you must only call GetLastError if FindWindow returnes NULL. – vlad_tepesch May 03 '13 at 09:18
  • Just a "me too" comment: I'm getting the same error on _some_ systems, too for calling `FindWindow` on "Shell_TrayWnd" as the first parameter. – Uwe Keim Dec 17 '13 at 15:42

1 Answers1

3

MSDN says, that FindWindowand FindWindowEx return NULL if the function fails and that you should check GetLastError. It seems that this documentation is wrong. Take this code fragment:

SetLastError(12345);
HWND h = FindWindow(L"class_name_that_does_not_exist", nullptr);
cout << h << ' ' << GetLastError() << endl;

It will output

00000000 12345

So as you can see FindWindow fails to set the last error. In your case this means that the ERROR_ALREADY_EXISTS was the last error set before FindWindow was called.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69