Console2 and x64

I recently mentioned that version 2.00b140 of the great Console utility had come out. Eddie Velasquez commented on that post that, unfortunately, Console didn't work correctly on Windows x64.

I had the opportunity to verify this during the last week. Console2 runs, but all text drawn on the console is invisible, which makes it a bit hard to read :-). I looked around the web, and although a few people mentioned seeing the same problem, no one offered any solutions. So I decided to take a look.

I installed Visual C++ 2008 on my x64 machine, downloaded the Console2 source code package and went hunting around for all dependencies needed to actually build it, which took a couple of hours. Off the top of my head, you need:

After a bit of tweaking the project files, I was able to build an x86 version of the code and started looking around the code to see where the problem might be. I checked a few things, like:

  • Was it possible that it was interacting incorrectly with the underlying system console and not picking up the text colors? Nope. Debugger showed me it was indeed picking up the right color for each character drawn.
  • Was it possible that it was mapping colors incorrectly? nope, not that either.
  • Was it possible it was drawing the text in the wrong locations? Didn't seem to be that either, as you could even copy paste the text from Console correctly, and the caret seemed to be at the right location either.
  • Could the off-screen surfaces be somehow invalid? Nope, a few calls to GetDeviceCaps() showed it had all the correct number of planes and bits per pixel that you'd expect.

After a few hours of tinkering, I was able to narrow it down to one issue: the use of the AlphaBlend() function when blitting between the off-screen and on-screen surfaces. In fact, I'm fairly confident that the issue Console2 is running into is the same one described on this newsgroup post. Unfortunately, that didn't seem to point to a good workaround for the issue.

Now, my GDI programming isn't very fresh on my mind, and frankly, I didn't want to sit around for a long time trying to get this fixed. However, I was able to make a quick change to the code that would make it work. The changes are setting up the BlendFunction for AlphaBlend slightly different.

The change I did was around line 1979, changing the setup before AlphaBlend like this:

blendFn.BlendOp               = AC_SRC_OVER;
blendFn.BlendFlags            = 0;
blendFn.SourceConstantAlpha   = 255;
blendFn.AlphaFormat           = AC_SRC_OVER;

Now, to be honest, this is just a hack, but it does the trick for now, using ClearType for font rendering and even alpha transparency on the entire window. I was not able (at least not in my quick look at the code) to fix the code path that gets executed when you're using an image as the console background, since that actually does require full alpha-blending to render the right output.

So it's not a great fix, but it means I can use Console2 on my x64 box now, which is good enough for me at this point. YMMV.

Comments (6)

Ben HoffsteinSeptember 19th, 2008 at 7:35 am

That’s great. I have been very eager to use Console2 on my Vista x64 machine. Any chance you’d be willing to share the binary somewhere?

Tomas RestrepoSeptember 19th, 2008 at 8:08 am

I don’t want to get in trouble for redistributing it publicly; I’d be much happier if the author managed to work around the issue (I may try when I have a bit more time to prepare a proper fix and share it).
However, send me an email and I’ll send you a copy.

Steven HarmanSeptember 19th, 2008 at 10:18 pm

Tomas,
I think the license would actually allow you to redistribute the modified code and binaries… and it might also be a good idea to submit a bug report (and your hack as a possible patch) at the Console2 site.
Just a suggestion – b/c I’d love to get ahold of a working copy of Console2 for x64 :)

Jason WestOctober 14th, 2008 at 7:48 am

Same here. Have Vista now and would love to get Console2 running on it. Any chance you could post the bin for download? If not, then see if you could submit your work back to the project at SourceForge.net so that they may publish it for download.

Tomas RestrepoOctober 14th, 2008 at 5:21 pm

Jason: I’m not going to post it; but feel free to send me an email and I’ll send you a copy of my compiled binaries.

tradsudNovember 5th, 2008 at 1:10 pm

Thomas, thank you! I’ve used Console for years, and with my new machine was severely missing it. With your post I was able to get it up and running again. Thanks for taking the time to share!
I’ve also posted the compiled exe on my blog if anyone else want’s to take advantage of it:
http://groke.org/blog/?p=75

Leave a comment

Your comment