I want to use the task dialog in my VC++ application. I am able to create a task dialog successfully using either TaskDialog or TaskDialogIndirect, and it works fine in Vista. However, I want my application to work on windows XP as well, and since windows XP does not support Task Dialog, I have created a dialog of my own that I want to use instead in case the OS is XP.
So my code does something like: if OS is Vista or higher: Show TaskDialog else Show my own dialog
Now the application still does not work in windows XP. When I attempt to start the application on XP, I get the error "The ordinal 345 could not be located in the dynamic link library comctl32.dll". This is possibly because the call to TaskDialogIndirect is there in my code, though the call is in an if block. While loading the application it attempts to locate the function in the comctl32.dll, and it does not find it since it is the XP version of the dll.
So my question is:
How do I code my application so that it runs successfully on both XP and Vista, and in case of XP show my own dialog box whereas in case of Vista and higher show the task dialog?
The problem is that your application has a dependency on those functions, a dependency that the OS loader tries to resolve at application start-up. But of course, those functions don't exist in XP, so the executable fails to load.
There are two ways around this. First, try delay-loading comctl32.dll. This should remove the load-time dependency and delay the resolution until the function is actually called. Then you just need to take care not to call it where it's not supported.
If that doesn't work, then you would have to bind to TaskDialog
explicitly, via LoadLibrary
and GetProcAddress
. This way, you never explicitly mention the function in a way that the linker would know about, so you don't take a load-time dependency on it. That's a bit more work though, mucking around with function pointers.