I came across a situation where I know the code
I created an MFC application in Visual Studio 2008 that generates a Tray icon and some notifications. I read that I can use a different NOTIFYICONDATA structure for Windows Vista than for Windows XP by setting the cbSize property of the structure to initialize it. I also read that I can use LoadIconMetric in Windows Vista to load my notification icon, while in Windows XP this function is not available to me and I have to use LoadIcon .
In my application, I installed the following:
#ifndef WINVER #define WINVER 0x0600 // Vista #endif #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0600 // Vista #end#if #ifndef _WIN32_WINDOWS #define _WIN32_WINDOWS 0x0600 // Vista #endif #ifndef _WIN32_IE #define _WIN32_IE 0x0700 #endif
I compile and link to the Windows 7 SDK on a Windows 7 x64 computer in Visual Studio 2008. My test for WindowsVista or higher looks like this (directly from MSDN):
static BOOL IsWinVistaOrLater() {
Now here is the interesting part. I use IsWinVistaOrLater to determine if I should use LoadIconMetric or LoadIcon:
if (IsWinVistaOrLater()) { tnd_Happy.dwInfoFlags = NIIF_LARGE_ICON | tnd_Happy.dwInfoFlags; LoadIconMetric(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_HAPPY), LIM_SMALL, &(tnd_Happy.hIcon)); } else { tnd_Happy.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE (IDI_ICON_HAPPY));
In XP, it crashes with "Ordinal 380 not found in ComCtrl32.dll." If I comment on the LoadIconMetric call, everything will be fine (even with all of these target versions installed for Vista). Does Windows try to import all function calls regardless of the execution code path?
source share