just adding the windows-target crate doesn’t help.
The thing is that I didn’t need to add anything when using QueryContextAttributesW it’s only QueryContextAttributesExW (Ex version) that cases the linker error
well, a static library is just a bunch of object files, in other words, a static library did not go through the linker. if the library is built as rlib and consumed by another rust crate, proper metadata (most importantly the linker flags) is preserved and maintained by cargo, that's where the windows-targets crate helps, since it emit special directives to cargo in it's build.rs.
however when it is consumed by C++, the C++ build tool doesn't have the proper linker input, thus the unresolved symbol. I see two possible solutions here, you either:
a) copy the import library provided by windows-targets crate and add that as the C++ linker input
b) resolve the symbol during the rust build process, by changing your build artifact from a static library to a dll, i.e. the cdylib crate type. unlike a static library, a dll is produced by the linker and the dependencies are resolved.
I ended up trying something "silly": use the SECPKG_ATTR_NAMES flag from the documentation of the Ex version with the non Ex version, and it worked O_O
So I use QueryContextAttributesW with SECPKG_ATTR_NAMES. I guess the underlying code is common or something