Comments (4)
Your code as written currently has a bug. Before formatting the message, WIL will "widen" the format string (to ensure that there's no "loss" of data when formatting Unicode strings). You should explicitly specify %hs
for narrow char*
strings
from wil.
More info from the documentation:
Be explicit when logging strings with XXXX_MSG macros. Use either: %ls or %hs to control whether an argument is a wide or ascii string, rather than using %s or %S. The format string is expected to be ASCII to minimize binary size, but internally is printed Unicode to avoid loss of data from params. Use the explicit format specifier to avoid the ambiguity this can bring.
from wil.
Thanks, I will fix it. If wil is interpreting a format string that is provided as char* as if it is wide, is there a way to provide a more helpful error message? Even if the comment on __WI_CHECK_MSG_FMT explained this, then I would have been able to fix the problem without opening this issue. As it is, this wil design is surprising and not everyone updating to a new version of wil will be familiar with this requirement.
from wil.
is there a way to provide a more helpful error message?
Depends on which part of the error message you find unhelpful. IIRC the vast majority of error messages I saw said something like:
warning C4477: 'wprintf' : format string '%s' requires an argument of type 'wchar_t *', but variadic argument 1 has type 'const char *'
note: consider using '%hs' in the format string
note: consider using '%Ts' in the format string
note: this warning is based on non-standard semantics used by Visual C++
That's fairly specific. The most confusing part is the reference to wprintf
. AFAIK there's no way to make that part better for two reasons:
- The check done by the compiler seems to be hard coded based off function name. Therefore, we have a limited set of options in terms of triggering the warning as something like
_Printf_format_string_
is unfortunately not checked by the compiler and you instead have to run additional tools to get warnings (e.g. compiling with/analyze
) - Even if the above were resolved, and
_Printf_format_string_
(or some other attribute) did work, we'd need a way to communicate to the compiler that we're going to be widening the string
Even if the comment on __WI_CHECK_MSG_FMT explained this, then I would have been able to fix the problem without opening this issue
If there's verbiage that would have been more helpful, feel free to submit a PR to clarify things.
from wil.
Related Issues (20)
- Standard facility to convert between ANSI and UNICODE. Similar to ATL::CA2W and ATL::CW2A HOT 2
- WI_FAIL_FAST_ASSERT missing semicolon HOT 1
- [prefast:Warning] C26495 wil::details::folder_change_reader_state::{ctor} HOT 1
- [prefast:Warning] C6387 wil::details::ProcessHeapAlloc HOT 1
- Accessing 32-bit registry view from 64-bit process
- Feature request: Add functions to enumerate Toolhelp32Snapshot
- Helpers for implementing Out Of Proc COM server in cppwinrt, without WRL
- key_iterator_data string corruption HOT 2
- CreateFileW helpers are marked noexcept but throw HOT 3
- try_copy_to should be noexcept?
- Compilation error with Microsoft.Windows.ImplementationLibrary.1.0.240122.1 HOT 2
- Output Stream for OutputDebugString
- Add a wil::zwstring_view ctor that accepts a wil::hstring HOT 1
- Feature request: when built with `/std:c++latest` or future `/std:c++23`, support `std::expected<>` for `wil::reg::try_*` HOT 1
- try_open_file is part of WIL_ENABLE_EXCEPTIONS block HOT 3
- Feature request: a path class HOT 3
- Feature: Add an RAII wrapper to support RPC timeouts when making blocking COM calls
- Support for using WIL from inside an Enclave HOT 1
- BuildAndTest timeout should be shorter than 6 hours HOT 1
- WIL is testing against an outdated version of cppwinrt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wil.