On Friday, 21 April 2023 at 15:05:03 UTC+1 Albrecht Schlosser wrote:
I propose to define _WIN32_IE (as in your example) right before
'#include <shlobj.h>' to avoid other potential side effects.
Please test attached diff if it works for you.
Tested in various configs; seems to be working fine, at least for me!
There's one issue with this patch though: it could happen that it
would #undef _WIN32_IE if it's not defined. Is this acceptable or
would it perhaps issue compiler warnings? I tested such a case with
'gcc -Wall -W -Wpedantic -Wextra' and didn't get warnings, but I
don't know if the standard "allows" it and didn't test with MS
compilers. We could make sure that this doesn't happen with another
#if defined(_WIN32_IE) but if it's not necessary we could just use
my patch as-is.
I do not know for sure - I have never (as far as I can recall, anyway!) ever seen a warning from #undef'ing a macro that was not actually defined, but TBH I have no idea what the standards say, or whether there may be some compiler that would complain.
Ian, if you test the patch and it works, would it be OK if I
committed it?
I'm happy with the patch, so go ahead with the commit.
If you are interested in a trivial "improvement" it might be to adjust the comment:
// notably header versions 5.3.0 and earlier, whereas 5.4.2 seems to define _WIN32_IE as needed.
Because I see it fail with mingw32 header version 5.0.2 also. But that's a minor observation so feel free to ignore!