Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.56k stars 572 forks source link

AllocConsole() doesn't attach to ConEmu #888

Open Borph opened 7 years ago

Borph commented 7 years ago

My program is doing something like the following:

HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE );
if( hOut == NULL ) {
  AllocConsole();
  SetConsoleTitle( TEXT("DBG stdout") );
  hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  hCrt = _open_osfhandle( (long) hOut, _O_TEXT );
  hf = _fdopen( hCrt, "w" );
  *stdout = *hf;
  setvbuf( stdout, NULL, _IONBF, 0 );
}

I have enabled DefaultTerm feature in settings and also see the DLL loaded in that process: C:\Users\user\AppData\Local\ConEmu\ConEmuHk.161002.dll.

Still, the application opens the default terminal window. I can go to ConEmu and attach to that process, though, but this also doesn't work always (don't know why).

I'm not owning above code, just used the fact that I have the source to find the AllocConsole(). Any hint why hooking doesn't open ConEmu automatically?

Versions

ConEmu build: 161002 stable x64 OS version: Windows 7 x64 Used shell version: git-bash (of git 2.10.0.windows.1)

ConEmuLogs/sys.exe-1552.log

2016-10-05 16:00:39.902 ConEmu 161002[32] log 16:00:39.913 "D:...\sys.exe" 16:00:39.916 DefTerm[1552]: InitDefaultTerm finished, calling StartDefTerm 16:00:39.948 DefTerm[3792]: CheckForeground x00010154 <<== trying to set hooks 16:00:39.948 DefTerm[3792]: "C:\Program Files\ConEmu\ConEmu\ConEmuC64.exe" /DEFTRM=3792 16:00:39.969 DefTerm[3792]: Service process PID=6064 started 16:00:39.981 DefTerm[3792]: Service process PID=6064 finished with code=144 16:00:39.981 DefTerm[3792]: CheckForeground x00010154 <<== nResult=144 iHookerRc=0

Maximus5 commented 7 years ago

You misunderstood the meaning of DefTerm! The feature allows users to run children console applications in ConEmu automatically. But you are talking about creation of console window in existing process / existing GUI application. Your app was already started outside of ConEmu and perhaps created some visible windows, doesn't it?

Borph commented 7 years ago

It's started from devenv.exe, but when from inside ConEmu it doesn't open the console window, I guess due to the check (hOut == NULL). Still no output then :-( Yes, it first opens the GUI window. I'm asking because Issue#55 suggested the DefaultTerminal feature!

Maximus5 commented 7 years ago

Ok, I'll fix it

Borph commented 7 years ago

Today I got it working, the app had the console in ConEmu automatically, but strangely it stopped again. Not sure why, I updated ConEmu to 161009a and rebased the app as well. Now the default terminal appears again :-( Will have a look in Git.