In C++/CX, hat pointers are contextually convertible to bool, but you can’t...
C++/CX is a language extension intended to make consuming the Windows Runtime easier. It is, however, no longer the C++ projection of choice. That honor now belongs to C++/WinRT, which allows you to...
View ArticleIn C++/WinRT, what happens when I treat an IInspectable as or convert one to...
Last time, we looked at weirdness in how C++/CX treats hat pointers in a bool context. Fortunately, C++/WinRT is much less weird. The IInspectable type supports a conversion to bool which tests whether...
View ArticleC++ coroutines: Getting started with awaitable objects
Coroutines were added to C++20, and Lewis Baker has a nice introduction to them. Coroutine theory. Understanding operator co_await. Understanding the promise type. But I’m going to write another one,...
View ArticleC++ coroutines: Constructible awaitable or function returning awaitable?
Last time, we learned how to create simple awaitable objects by creating a structure that implements the await_suspend method (and relies on suspend_always to do the coroutine paperwork for us). We...
View ArticleC++ coroutines: Framework interop
So far, we’ve been looking at the basics of awaitable objects. Even though we barely know anything beyond await_suspend, we already know enough to allow us to start diving deeper. It is frequently the...
View ArticleC++ coroutines: Awaiting an IAsyncAction without preserving thread context
The C++/WinRT library provides an awaiter for Windows Runtime asynchronous activities. Those asynchronous activities are represented by IAsyncAction, IAsyncOperation, and progress versions of the...
View ArticleC++ coroutines: Short-circuiting suspension, part 1
At the start of this series, I gave the basic idea for how the compiler generates code for co_await, but I left out some details for expository simplicity. There are some mysterious steps called...
View ArticleC++ coroutines: Short-circuiting suspension, part 2
There’s one last section of the outline of compiler code generation for co_await that is marked “We’re not ready to talk about this step yet.” Let’s talk about that step. Before suspending the...
View ArticleC++ coroutines: no callable ‘await_resume’ function found for type
You try to co_await something and get the error message no callable ‘await_resume’ (or ‘await_ready’ or ‘await_suspend’) function found for type ‘Expression’ What does this mean? Recall how the...
View ArticleC++ coroutines: Defining the co_await operator
At the start of this series, I noted that there are three steps in obtaining an awaiter for an awaitable object. The first two were marked “We’re not read to talk about this yet.” Well, now we’re...
View ArticleC++ coroutines: The co_await operator and the function search algorithm
So you’re following along Kenny Kerr’s blog and you get to the part where he uses co_await on a time duration: co_await 5s; so you try it: #include <chrono> using namespace std::chrono;...
View ArticleC++ coroutines: The problem of the synchronous apartment-changing callback
Today is a puzzle you can you can try to solve with the information you’ve learned about C++ coroutines and C++/WinRT. C++/WinRT uses the IContextCallback interface to remember the context that...
View ArticleC++ coroutines: The problem of the DispatcherQueue task that runs too soon,...
I was experiencing occasional crashes in C++/WinRT’s resume_foreground function when it tries to resume execution on a dispatcher queue. Here’s a simplified version of that function: auto...
View ArticleC++ coroutines: The problem of the DispatcherQueue task that runs too soon,...
Last time, we discovered a race condition in C++/WinRT’s resume_foreground(DispatcherQueue) function when it tries to resume execution on a dispatcher queue. Let’s try to fix it. As a reminder,...
View ArticleC++ coroutines: The problem of the DispatcherQueue task that runs too soon,...
Last time, we fixed a race condition in C++/WinRT’s resume_foreground(DispatcherQueue) function when it tries to resume execution on a dispatcher queue. We did this by having the queued task wait...
View ArticleC++ coroutines: The problem of the DispatcherQueue task that runs too soon,...
Last time, we made another attempt to fix a race condition in C++/WinRT’s resume_foreground(DispatcherQueue) function when it tries to resume execution on a dispatcher queue. We did this by having...
View ArticleControversial extension methods: CastTo and As
You’ve probably had to do this in C#. You get an object, you need to cast it to some type T and then fetch a property that is returned as an object, so you have to cast that to some other type U, so...
View ArticleHow do I make a clone of a Windows Runtime vector in C++/CX?
There are still some people maintaining code bases written in C++/CX, even though C++/WinRT is the new hotness. Suppose you have a reference to a Windows Runtime vector in C++/CX, either an...
View Article2019 year-end link clearance: The different kinds of DLL planting
This time, the link clearance is just one link: Triaging a DLL planting vulnerability. That link summarizes various causes of alleged DLL planting vulnerabilities and how the Microsoft Security...
View ArticleNasty gotcha: Positioning your window beneath a topmost window makes it topmost
There’s a nasty gotcha with the DeferWindowPos function, and therefore any functions built on top of it, such as SetWindowPos: If you specify a hwndInsertAfter, and the insert-after window is...
View Article