microsoft / microsoft/Windows-classic-samples

CloudMirror sample and CustomStateProvider lifetime.

Open
#239 0 comments 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

I want to implement a custom version of the separate COM exe server with lifetime management and ref counting of handlers (https://docs.microsoft.com/en-us/windows/win32/com/out-of-process-server-implementation-helpers).

I have added a debug output into constructors and destructors of handlers to inspect their lifetime.

static std::atomic<int> instanceCounter;

CustomStateProvider::CustomStateProvider()
{
    OutputDebugString((L"CustomStateProvider constructor called (instance counter: " + std::to_wstring(++instanceCounter) + L")\n").c_str());
}

CustomStateProvider::~CustomStateProvider()
{
    OutputDebugString((L"CustomStateProvider destructor called (instance counter: " + std::to_wstring(--instanceCounter) + L")\n").c_str());
}

For some reason, the CustomStateProvider constructor gets called more times than its destructor. Even if I close all explorer instances and finish the application. Is this a bug in SDK?

CustomStateProvider constructor called (instance counter: 1)
CustomStateProvider constructor called (instance counter: 2)
CustomStateProvider destructor called (instance counter: 1)          <-- last time CustomStateProvider destructor gets called
TestExplorerCommandHandler constructor called (instance counter: 1)
TestExplorerCommandHandler destructor called (instance counter: 0)
TestExplorerCommandHandler constructor called (instance counter: 1)
TestExplorerCommandHandler destructor called (instance counter: 0)
TestExplorerCommandHandler constructor called (instance counter: 1)
TestExplorerCommandHandler destructor called (instance counter: 0)
ThumbnailProvider constructor called (instance counter: 1)
ThumbnailProvider destructor called (instance counter: 0)
ThumbnailProvider constructor called (instance counter: 1)
ThumbnailProvider destructor called (instance counter: 0)
ThumbnailProvider constructor called (instance counter: 1)
ThumbnailProvider destructor called (instance counter: 0)
ThumbnailProvider constructor called (instance counter: 1)
ThumbnailProvider destructor called (instance counter: 0)
ThumbnailProvider constructor called (instance counter: 1)
ThumbnailProvider destructor called (instance counter: 0)

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 the CloudMirror sample and its CustomStateProvider entry point, then compare the logged constructor and destructor counts with the COM out-of-process server lifetime guidance linked in the issue. Determine whether the unmatched instance reflects a sample or SDK lifetime problem, and document the verified ownership behavior or a reproducible correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.