windev
windev

Reputation: 49

FindWindow error 183

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?

Upvotes: 4

Views: 1397

Answers (1)

Werner Henze
Werner Henze

Reputation: 16781

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.

Upvotes: 3

Related Questions