一个控制台程序,因为引用的lib中的某些代码,也静态链接了 comctl32.dll, 但启动时会报下面错误:
image.png
但奇怪的是引用同样库的其它带界面的几个程序并未出现同样错误,使用工具发现控制台程序链接到的是 C:\windows\system32\Comctl32.dll, 而未出错的链接到的是
C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22000.120_none_9d947278b86cc467\comctl32.dll
也就是说某种因素导致了它们链接到了不同的dll,而系统中的这个又缺少了导出函数345.
再使用工具对比,它们的manifest不同,正常的界面程序中已经包含了'6.0.0.0' 版本的'Microsoft.Windows.Common-Controls',而控制台程序则未包含.
所以以某个公共头文件中添加下面代码解决这个问题.
#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif