Is it possible to determine if the application has a console window? Either use AllocConsole, or use this regular console application.
Edit:
Solution (thanks to the ho1 answer):
public static class ConsoleDetector
{
private const uint ATTACH_PARENT_PROCESS = 0x0ffffffff;
private const int ERROR_ACCESS_DENIED = 5;
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32", SetLastError = true)]
private static extern bool FreeConsole();
public static bool HasOne
{
get
{
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
FreeConsole();
return false;
}
return Marshal.GetLastWin32Error() == ERROR_ACCESS_DENIED;
}
}
}
source
share