Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7504319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:32:08+00:00 2026-05-29T21:32:08+00:00

I am facing numerous crashes on a application which is heavily multi-threaded. Reading these

  • 0

I am facing numerous crashes on a application which is heavily multi-threaded.

Reading these MSDN page, technical note and this article on TLS, I have understood that CWnd objects are mapped to HWND in the Thread Local Storgae (TLS, which is a thread dependendent memory access).

I was going to decouple everything that looks like CWnd thread-remote access, and transform it into HWND references and then use ::PostMessage as communication port.

But one of my colleagues really insisted that I just keep the CWnd* in the foreigner threads, adopt the ::PostMessage policy ok, but use CWnd::GetSafeHwnd() or the pMyCWnd->m_hWnd in the foreign threads so as to recover the native HWND.

I have been arguing that nowhere I have seen that the GetSafeHwnd() is threadsafe, and that the CWnd objet being in the TLS, it’s value in another thread is different.

I am wrong ? The MSDN is clearly using the term Unexpected results.

What’s your point of view, about calling CWnd::GetSafehwnd() or pMyCWnd->m_hWnd in outer threads from the creator thread ?

Do you have any MSDN documentation that states that this is safe or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:32:14+00:00Added an answer on May 29, 2026 at 9:32 pm

    CWnds are not mapped to HWNDs; HWNDs are mapped to CWnds, and this happens on a per-thread basis. The CWnd object is not in TLS (how would that work?) but temporary CWnd objects are created per-thread.

    Accessing a temporary CWnd object from the wrong thread is definitely a bad idea (for the reasons described by Mark Ransom).

    However, if you have a permanent CWnd object (representing the main window of your app, say) then, once it is created, there is no problem at all in accessing the m_hWnd member from any thread. It’s just a value in memory that never changes.

    If this troubles you (because it’s not explicitly documented) then simply make a copy of the HWND and let the threads access that.

    P.S. Here’s the article you linked to in English.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im facing a problem. I have a listing page in which i list all
Am facing few issues with multi step transction in hibernate. This is what I
Im facing a Problem my HDD died and I lost many application which I
Firstly, this is not a question about repository synchronisation for which there are numerous
When facing the problem of validating a property in a JSF2 application there are
I'm facing a problem with IE6. I took the toggle function from this website
I am facing an application designed to import huge amounts of data into a
I have some internal-facing ASP.NET web services that have had numerous API additions over
Im facing an issue which I believe to be VAO-dependant, but Im not sure..
I´m facing a huge problem since a couple weeks. I´ve an asp.net application hosted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.