Friday, December 25, 2009

Manifest gotchas

For those of you using Visual Studio 2008, and using it’s C++ TR1 support in SP1, here’s something I wish I hadn’t spent so much time tracking down..

TR1 features only exist in 2008 SP1, but the linker will happily build a manifest to link against the pre-SP1 CRT even if you’re using TR1. Some systems (including your development machines) will have proper side-by-side library redirection from the old CRT to the new one. But machines with the old runtime installed won’t fail to load the DLL, they’ll just mysteriously fail to find symbols in it. For example, one machine failed to find std::tr1::weak_ptr and gave the following error:

The procedure entry point ?_Xweak@tr1@std@@YAXXZ could not be located in the dll MSVCP90.dll

The solution is to force your project’s manifest to specify the lastest CRT version by defining the following macro:

_BIND_TO_CURRENT_CRT_VERSION
Microsoft’s full explanation is here: http://msdn.microsoft.com/en-us/library/cc664727.aspx

Friday, February 27, 2009

Multi-button Input Devices


Keyboards are important to me.
I used to love pretty, low-profile scissor-key style keyboards. After trying a ergonomic keyboard a few years ago and having it relieve my occasional wrist pain, I never went back. Typing on a non-split keyboard even feels strange now. For about two years I've been using the Microsoft Natural Ergonomic 4000 Keyboard both at home and at work. There are a bunch of reasons that this is my favorite keyboard lately: the keys have a very solid action (not as much as the wonderful old IBM Model M, sadly), the enter key is on a single line (as opposed to keyboards with backwards-L shaped enter keys, which push the \ key to be moved elsewhere, often making for a smaller backspace key) and the angle and split of the keyboard has really helped my wrists.
One thing the keyboard does leave to be desired is a better set of media keys. The only "extra" keys I ever end up using on a keyboard are the media keys, so that I can control iTunes without context-switching.
Getting the media keys to control iTunes at all was a pain - iTunes only wanted to respond when it had focus, which obviously is missing the point. A while back I discovered an iTunes plugin called mmKeys which registered global hot keys for using media keys, which fixed that problem. The next problem, which I've been living with for a while, is that this keyboard has a play/pause button, and that's it. If a song comes on that's distracting me from working, I need to further distract myself by opening iTunes and skipping it. The keyboard does, however, have browser back and forward buttons, which seem perfect for re-mapping to track skip buttons. So last week I actually installed the drivers for the keyboard at home for the first time; the driver control panel has a utility for reassigning any key to a series of built-in functions. That didn't quite work as expected - the play/pause button actually causes my media player window to raise and gain focus. Again, obviously missing the point.
Fortunately, the driver's control panel does let you set a program to start when the key is pressed, instead of an action off of the default list. I googled around for command-line options to iTunes or APIs that I could use to write simple scripts for each action, and discovered someone had already done it for me. I've installed these scripts, and now I have exactly the control scheme I want.
Hopefully, by writing up my solution, I'll have an easier time configuring my next machine. And just maybe I'll help out someone googling for the answer too.