Hi,
I am building a Win32 application using WinUI2 as GUI.
Before displaying a window to the user, we are checking our Desktop capabilities from the Operating System has shown below.
bool
CheckDesktop () noexcept
{
HDESK thread_desktop;
uint32_t rc;
thread_desktop = ::GetThreadDesktop (::GetCurrentThreadId ());
if (!thread_desktop)
return false;
// Expected size of buffer (rc here) is 4 bytes. So,
// use uint32_t buffer type instead of Bool.
if (::GetUserObjectInformationA (thread_desktop, UOI_IO, &rc, sizeof (rc), nullptr) == 0)
return false;
if (rc != 1)
return false;
return true;
}
We have chosen our application in such a way that if this above function returns false, we don't start our application and exit it from there.
If the above function returns false, we say that application is running in non-GUI environment.
But along with this, we have registered for WER framework as shown below:
int WINAPI
wWinMain ([[maybe_unused]] HINSTANCE pInstance, [[maybe_unused]] HINSTANCE pPrevInstance, [[maybe_unused]] PWSTR pCmdLine, [[maybe_unused]] int pShowCmd)
{
if (!CheckDesktop ())
return 1;
// ... Some other calls
// Registering for WER
HRESULT hresult;
hresult = ::RegisterApplicationRestart (nullptr, RESTART_NO_PATCH | RESTART_NO_CRASH | RESTART_NO_HANG);
}
Stating a scenario,
User launches the application CheckDesktop func will return true and WER registration succeeds. As WER is registered so the application will come back upon restart but that is not working as expected because when the application starts by WER the 'CheckDesktop ()' returns false due to which my application exits.
As stated in Desktops "The Winlogon desktop is active while a user logs on. The system switches to the default desktop when the shell indicates that it is ready to display something, or after thirty seconds, whichever comes first."
I understand that OS might take some time for this switch, but can somebody help me in what should be done for my CheckDesktop function to return true in the case where application was started by WER?
Thanks