Click here to Skip to main content
15,909,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Visual Studio .Net - files in workspace aren't alphabetical Pin
Mike Nordell17-Apr-02 12:22
Mike Nordell17-Apr-02 12:22 
QuestionVirtual desktops? Pin
generic_user_id17-Apr-02 9:35
generic_user_id17-Apr-02 9:35 
AnswerRe: Virtual desktops? Pin
Mike Nordell17-Apr-02 9:54
Mike Nordell17-Apr-02 9:54 
GeneralRe: Virtual desktops? Pin
generic_user_id17-Apr-02 11:10
generic_user_id17-Apr-02 11:10 
GeneralRe: Virtual desktops? Pin
Mike Nordell17-Apr-02 11:59
Mike Nordell17-Apr-02 11:59 
GeneralRe: Virtual desktops? Pin
generic_user_id18-Apr-02 4:02
generic_user_id18-Apr-02 4:02 
GeneralA CPropertySheet, a CPropertyPage and a thread. Oh dear. Pin
17-Apr-02 9:22
suss17-Apr-02 9:22 
GeneralRe: A CPropertySheet, a CPropertyPage and a thread. Oh dear. Pin
Joaquín M López Muñoz17-Apr-02 9:57
Joaquín M López Muñoz17-Apr-02 9:57 
The problem is a very frequent one, and stems from the fact that CWnd-derived objects do funny things across threads. The explanation is a little long, please bear with me:
Given a Cwnd, its associated HWND handle is simply stored in the m_hWnd member. The other way around, obtaining the associated CWnd from a given HWND, is not that simple. There's no easy way to have Win32 store some pointer to the CWnd inside the data hold for a particualr HWND. To work around this problem, MFC guys decided to keep a global map of HWNDs to CWnd pointers. Now comes the key point: for historical and performance reasons, this HWND to CWnd map is not unique, but instead each thread has its own, stored in so called thread local storage (TLS). In your particular case, the worker thread is given a pointer to CPropPage. So far so good. But when GetParent is called, the following sequence of events happen:
  1. Win32 ::GetParent is called, returning a valid HWND.
  2. The associated CWnd is sought for, and as there is none local to this thread, a mock-up one is created (and inserted into the map). This object is not the CPropertySheet you began with.
And the rest is easy. GetPage fails because it is issued on a CWnd constructed out of nothing, with no information about the original CPropertySheet (apart from being associated to the same HWND.)
Calls to methods of caller will work OK nevertheless, as this time caller is actually the real object.
The moral of this story is: don't pass CWnd pointers across threads.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
QuestionCombo Box Uneditable? Pin
17-Apr-02 9:06
suss17-Apr-02 9:06 
AnswerRe: Combo Box Uneditable? Pin
Shog917-Apr-02 9:10
sitebuilderShog917-Apr-02 9:10 
GeneralRe: Combo Box Uneditable? Pin
17-Apr-02 9:14
suss17-Apr-02 9:14 
GeneralCArchive, Serialization and Versions Pin
Ted Christiansen17-Apr-02 8:44
Ted Christiansen17-Apr-02 8:44 
GeneralRe: CArchive, Serialization and Versions Pin
Mike Nordell17-Apr-02 8:47
Mike Nordell17-Apr-02 8:47 
GeneralRe: CArchive, Serialization and Versions Pin
Joaquín M López Muñoz17-Apr-02 8:58
Joaquín M López Muñoz17-Apr-02 8:58 
GeneralMessageBox crash Pin
17-Apr-02 8:40
suss17-Apr-02 8:40 
GeneralRe: MessageBox crash Pin
Joaquín M López Muñoz17-Apr-02 8:42
Joaquín M López Muñoz17-Apr-02 8:42 
GeneralRe: MessageBox crash Pin
17-Apr-02 8:54
suss17-Apr-02 8:54 
GeneralRe: MessageBox crash Pin
Joaquín M López Muñoz17-Apr-02 9:00
Joaquín M López Muñoz17-Apr-02 9:00 
GeneralRe: MessageBox crash Pin
17-Apr-02 9:30
suss17-Apr-02 9:30 
GeneralRe: MessageBox crash Pin
Joaquín M López Muñoz17-Apr-02 9:37
Joaquín M López Muñoz17-Apr-02 9:37 
GeneralRe: MessageBox crash Pin
Mike Nordell17-Apr-02 8:52
Mike Nordell17-Apr-02 8:52 
GeneralRe: MessageBox crash Pin
Tim Deveaux17-Apr-02 11:06
Tim Deveaux17-Apr-02 11:06 
GeneralCommerce Server 2000 Pipeline DLL Pin
Ollie17-Apr-02 8:33
Ollie17-Apr-02 8:33 
GeneralRe: Commerce Server 2000 Pipeline DLL Pin
Le centriste17-Apr-02 9:46
Le centriste17-Apr-02 9:46 
GeneralVisual Studio .net Pin
Member 9617-Apr-02 8:25
Member 9617-Apr-02 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.