Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllocConsole() doesn't attach to ConEmu #888

Open
Borph opened this issue Oct 5, 2016 · 4 comments
Open

AllocConsole() doesn't attach to ConEmu #888

Borph opened this issue Oct 5, 2016 · 4 comments

Comments

@Borph
Copy link

@Borph Borph commented Oct 5, 2016

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
Copy link
Owner

@Maximus5 Maximus5 commented Oct 5, 2016

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
Copy link
Author

@Borph Borph commented Oct 5, 2016

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
Copy link
Owner

@Maximus5 Maximus5 commented Oct 6, 2016

Ok, I'll fix it

@Borph
Copy link
Author

@Borph Borph commented Oct 11, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.