microsoft / microsoft/Windows-classic-samples

Win7Samples/multimedia/DirectWriteCustomLayout throws exception

Open
#362 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
5.7k
Forks
3.3k
PR merge metrics
No merged PRs in 30d

Description

After retargeting this project for VS 2022 and fixing a few minor issues (e.g. min() max() macros defined in Common.h conflicting with std functions), the project builds. However, when run, a main window is show with no client content, and then after some seconds the app automatically terminates.

On debugging, it is consistently throwing an exception before it has finished initializing (in MainWindow::Initialize()).

The implementation has a MainWindow class that holds the hwnd (and other stuff in protected members). When the call to CreateWindow() returns, it is not setting hwnd_; rather, a pointer to the MainWindow object is passed so that the object can be retrieved when WM_NCCreate is processed and hwnd_ is set then.

However, when ShowWindow() is called, a WM_SIZE message gets processed, and the OnSize() handler calls GetClientRect(hwnd_, &rect)
which throws because hwnd_ isn't set or can't be accessed. I tried changing the OnSize() signature to pass down the hwnd, but that still didn't work. I don't understand why a method within the MainWindow object can't access the hwnd_ protected member within that object.

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 by running the Win7Samples/multimedia/DirectWriteCustomLayout sample under the debugger and tracing MainWindow::Initialize(), ShowWindow(), and OnSize(). Inspect the MainWindow implementation and Common.h in the sample, then confirm the initialization no longer throws during WM_SIZE and the application does not terminate immediately.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.