(WinAPI) FindWindowW always fails

Deen O'Connor deen.oconnor at yandex.ru
Thu Oct 8 19:39:05 UTC 2020


I was coding my project, and at some point it required to get 
widow rectangle. GetWindowRect function returned 
ERROR_INVALID_WINDOW_HANDLE (0x578) error. This is where i 
detected the error. I then checked what the return value of 
FindWindowW was, and it was 0. GetLastError showed that there was 
ERROR_NOT_ALL_ASSIGNED (0x514) error.

So, to re-create the error, i did the following:
1 - Opened an app that has a window. In my case this was x32dbg, 
i chose it because it has a short window name without any spaces.
2 - Wrote a small program to check if the error will happen again:
import std.stdio;
import std.conv;
import core.sys.windows.windows;

void main(string[] args) {
     wstring wndName = "x32dbg";
     HWND hWnd = FindWindowW(null, cast(wchar*)&wndName);
     if (hWnd is null) {
         writeln("Error 0x" ~ to!string(GetLastError(), 16) ~ " in 
FindWindowW()!");
     } else {
         writeln("x32dbg window: 0x" ~ to!string(cast(uint)hWnd, 
16));
     }
}
3 - Ran this code with rdmd

Output said that there was an error.
This also happened with every window i tried to find no matter 
what. FindWindowA also failed.

The only reason i'm writing this is because i can find the window 
with x32dbg and a very similar C++ code works fine.
So, am i doing something wrong, or is this a bug?


More information about the Digitalmars-d mailing list