February 2023

Writing Native Win32 Applications with WinLamb and Modern C++ -- Richard Thomson

Utah C++ Programmers has released a new video:

Writing Native Win32 Applications with WinLamb and Modern C++

by Richard Thomson

From the video description:

The Win32 Windows API has been around for decades as a C API for GUI applications. At its heart, every Win32 application is a program that receives messages from Windows, decodes those messages and dispatches them to appropriate code for handling the message.

Graphical user interfaces are a natural fit for object oriented programming and C++ GUI frameworks like MFC (Microsoft Foundation Classes) were created to make writing GUI applications easier.

As Win32 applications evolved to incorporate COM (Component Object Model) objects, a need to write small components adhering to well defined interfaces became more important. Writing such components with MFC results in a heavyweight object and additional deployment dependencies. C++ libraries like ATL (Active Template Library) addressed the need to create interoperable binary components that were lightweight with minimal or no deployment dependencies.

The Windows Template Library (WTL) took the lessons learned from writing small COM objects with ATL and applied them to writing complete Win32 applications. The result is a complete library for writing Win32 applications using the static polymorphism of templates instead of the dynamic polymorphism of MFC.

Are there other ways to look at writing Win32 applications?

WinLamb is similar to WTL in that they are both header-only libraries that wrap the Win32 API. While a WTL program uses message map macros to select the appropriate handler for a message, WinLamb uses lambda functions for the message handlers and an internal dispatching mechanism.

This month, Richard Thomson will give us a walk through of using WinLamb to create Win32 applications. We'll look at how to create an application from scratch with CMake and using the project wizard in Visual Studio. (Since our application isn't cross-platform, but Windows only, we won't lose anything by using Visual Studio's wizard.)

From this skeleton application, we'll look at:

  • how to add message handlers to the main window
  • how to add controls to the main window
  • how to define and use resources
  • how to use a dialog box as the main window
  • how to separate GUI logic from application logic
  • Win32 API helpers provided by WinLamb

https://www.youtube.com/watch?v=2K52YX-vHv4

The C++ Language: Present and Future -- Daniel Garcia

This year we had a wonderful C++ start at Universidad Carlos III de Madrid. The Department of Computer Science and Engineering was honored to have Prof. Bjarne Stroustrup giving a seminar on C++ to start the semester.

We are always happy to have Bjarne Stroustrup with us. Since 2019 he holds a Honorary Doctorate by Universidad Carlos III de Madrid and he has visiting us several times.

Both talks were very well attended with a nice mix of professional developers from industry, students (bachelor, masters and PhD) and researchers and professors from several different departments.

This is a short summary of the two talks he gave:

Day 1: C++ 20: Reaching the aims of C++.

About the video

Out of necessity C++ has been an evolving language. I outline some early ideals for C++, some techniques for keeping the evolution directed, and show how C++20 comes close to many of those ideals. Specific topics ncludes type-and-resource safe code, generic programming, modularity, the elimination of the preprocessor, and error handling. Naturally, over the years, C++ has acquired many “barnacles” that can become obstacles to developing elegant and efficient code. That has been a recognized problem since the early days of C – Dennis Ritchie and I talked about it – so we must distinguish between what can be done and what should be done. The C++ Core Guidelines is the current best effort in that direction.

Day 2: Type-and-resource Safe programming in ISO Standard C++.

About the video

You can write C++ with no violations of the type system, no resource leaks, no memory corruption, no garbage collector, no limitation of expressiveness or performance degradation compared to well-written modern C++. This talk show how this can be achieved – and guaranteed – by the applying the C++ Core Guidelines, simple supporting libraries (mostly the ISO C++ standard library), and static analysis.

Many examples demonstrate how this can be done with code that’s dramatically simpler than older C++ (and C) code. This talk will touch upon RAII, type deduction, span, range checking, nullptr, initialization, invalidation,  casting and variants.


 

Review of Embracing Modern C++ Safely (Lakos, Romeo, Khlebnikov, Meredith) -- Bartlomiej Filipek

embcpp_small.jpgThe "Safely Tome" has landed, and we have a review from the author of C++ Stories:

Review of Embracing Modern C++ Safely (Lakos, Romeo, Khlebnikov, Meredith)

by Bartlomiej Filipek

From the review:

C++11 has been around for around 11 years and C++14 for 8. From my experience, I see that even today, many companies struggle to use those standards in production in the most efficient way. As always, with new stuff came benefits, risks, and increased learning effort. Fortunately, with a new book written by top C++ Experts, we have a solid guide on what is safe and what might be problematic in Modern C++.

The book is called “Embracing Modern C++ Safely”.

Let’s see what’s inside...

Overload 173, February 2023

overload173cover.pngOverload #173 is now available!

Highlights include:

  • Floating-Point Comparison  WEB  PDF
    By Paul Floyd
    Comparing floating point values can be difficult. Paul Floyd shows how you should perform floating-point comparisons (and how not to do it).

 

  • Determining If A Template Specialization Exists  WEB  PDF
    By Lukas Barth
    How do you tell if a class or function template can be used with specific arguments? Lukas Barth details his approach.

 

  • Stack Frame Layout On x86-64  WEB  PDF
    By Eli Bendersky
    Stacks can have different layouts. Eli Bendersky describes the x86-64 layout in detail.

 

  • Value-Oriented Programming  WEB  PDF
    By Lucian Radu Teodorescu
    The research Val programming language uses value-oriented programming. Lucian Radu Teodorescu explores this paradigm.

C++23 “Pandemic Edition” is complete -- Herb Sutter

image.pngC++23 is done!

C++23 "Pandemic Edition" is complete (Trip report: Winter ISO C++ standards meeting, Issaquah, WA, USA)

by Herb Sutter

From the article:

On Saturday, the ISO C++ committee completed technical work on C++23 in Issaquah, WA, USA! We resolved the remaining international comments on the C++23 draft, and are now producing the final document to be sent out for its international approval ballot (Draft International Standard, or DIS) and final editorial work, to be published later in 2023...

... Per our published C++23 schedule, this was our final meeting to finish technical work on C++23. No features were added or removed, we just handled fit-and-finish issues and primarily focused on finishing addressing the 137 national body comments we received in the summer’s international comment ballot (Committee Draft, or CD). You can find a list of C++23 features here, many of them already implemented in major compilers and libraries. C++23’s main theme was “completing C++20,” and some of the highlights include module “std”, “if consteval,” explicit “this” parameters, still more constexpr, still more CTAD, “[[assume]]”, simplifying implicit move, multidimensional and static “operator[]”, a bunch of Unicode improvements, and Nicolai Josuttis’ personal favorite: fixing the lifetime of temporaries in range-for loops...

The Toggle Builder -- Marco Arena

The toggle builderThat little extra we might equip builder classes with:

The Toggle Builder

by Marco Arena

From the article:

If intended for general usage, the builder can result a bit uncomfortable when we go through some configuration object to toggle features. This often leads to a bunch of ifs..

Numbers are not easy -- Šimon Tóth

1*sWhjlJxDvV6icGVeO_cV8A.pngAs the blurb says, "The C++ integral and floating-types zoo"...

Numbers are not easy

by Šimon Tóth

From the article:

Arguably one of the most error-prone parts of C++ is integral and floating-point expressions. As this part of the language is inherited from C, it relies heavily on fairly complex implicit conversion rules and sometimes interacts unintuitively with more static parts of C++ language.

This article will cover the rules and several surprising corner cases one can encounter when working with integral and floating-point types and expressions...

Regular Types -- Rainer Grimm

PortraintRound-1.jpgAs opposed to quirky eccentric ones...

Regular Types

by Rainer Grimm

From the article:

The term concrete type is strongly related to the term regular type. Let me, therefore, start this post with the term concrete type...