You're not checking the return result from FindTextW
. That is, you have:
findDialog = FindTextW(&fr);
cout << GetLastError() << endl;
If the function succeeds, the result is a handle. If the function fails, the return value is NULL.
According to the documentation:
If the function fails, the return value is NULL. To get extended error information, call the CommDlgExtendedError function. CommDlgExtendedError may return one of the following error codes:
In other words, GetLastError
isn't going to tell you anything meaningful. Call CommDlgExtendedError
after you check the handle to see if it's NULL.