Visual C++ 2005 will generate manifests for you

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon