May 31st, 2007

Visual C++ 2005 will generate manifests for you

New in Visual C++ 2005 is the ability to specify a manifest dependency via a #pragma directive. This greatly simplifies using version 6 of the shell common controls. You just have to drop the line

// do not use - see discussion below
#pragma comment(linker, \
    "\"/manifestdependency:type='Win32' "\
    "name='Microsoft.Windows.Common-Controls' "\
    "version='6.0.0.0' "\
    "processorArchitecture='X86' "\
    "publicKeyToken='6595b64144ccf1df' "\
    "language='*'\"")

into your program and the linker will do the rest.

Note that the processor architecture is hard-coded into the above directive, which means that if you are targetting x64, you’ll get the wrong manifest. To fix that, we need to do some preprocessor munging.

#if defined(_M_IX86)
#define MANIFEST_PROCESSORARCHITECTURE "x86"
#elif defined(_M_AMD64)
#define MANIFEST_PROCESSORARCHITECTURE "amd64"
#elif defined(_M_IA64)
#define MANIFEST_PROCESSORARCHITECTURE "ia64"
#else
#error Unknown processor architecture.
#endif
#pragma comment(linker, \
    "\"/manifestdependency:type='Win32' "\
    "name='Microsoft.Windows.Common-Controls' "\
    "version='6.0.0.0' "\
    "processorArchitecture='" MANIFEST_PROCESSORARCHITECTURE "' "\
    "publicKeyToken='6595b64144ccf1df' "\
    "language='*'\"")

Update: I didn’t know that * is allowed here to indicate “all architectures”. That simplifies matters greatly.

#pragma comment(linker, \
    "\"/manifestdependency:type='Win32' "\
    "name='Microsoft.Windows.Common-Controls' "\
    "version='6.0.0.0' "\
    "processorArchitecture='*' "\
    "publicKeyToken='6595b64144ccf1df' "\
    "language='*'\"")

Nitpicker’s corner

* That wasn’t a footnote marker.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.