This is not 100% fool proof. How ever in normal cases, this works great. This technique can be used to find out, whether the child application was launched from a GUI application or from a Console application.
if( AttachConsole( ATTACH_PARENT_PROCESS ))
{
AfxMessageBox( _T("Parent process is a console application"));
}
else
{
AfxMessageBox( _T("Parent process is not a console application"));
}
Hi Naveen,
ReplyDeleteAnother method would be iterating all of the parent process threads and calling the IsGUIThread Function to check if the Win32 subsystem (Win32k.sys) has promoted the thread. If any of the threads return TRUE then the parent process has a non-console window.
Best Wishes,
-David Delaune (Randor)
Hi David,
ReplyDeleteBut that function needs to be called from the thread context, isnt it?