microsoft / microsoft/wil

simple_event seems to be unusable - Compilation error with wil::simple_event, const vs non-cost handler.

Open
#348 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3k
Forks
300
Avg merge
19h 12m
Merged PRs (30d)
1

Description

Attempting to use wil::simple_event with C++/winrt generated code yields compilation errors.

The C++/winrt generated code is similar to:
*token = detach_fromwinrt::event_token(this->shim().MyEvent(reinterpret_cast<winrt::Windows::Foundation::EventHandler const>(&handler)));

This is supposed to call this function in event_base:
winrt::event_token operator()(T&& handler)
{
return m_handler.add(std::forward(handler));
}

But it can't cast the const handler from the C++/winrt generated code to the non-const in wil::details::event_base.

Note the original concept code from Raymond Chen's blog on this originally used const and can be used with C++/winrt.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with wil::details::event_base and its operator() overload, then compare the const handler passed by the shown C++/WinRT-generated call with the original concept described in the issue. Reproduce the compilation error with wil::simple_event and confirm done when the generated-code pattern compiles without breaking existing handler usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.