Click here to Skip to main content
16,006,001 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Visual Studio .Net - files in workspace aren't alphabetical Pin
Anders Molin17-Apr-02 11:59
professionalAnders Molin17-Apr-02 11:59 
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 
Hello there,

This isn't so much a problem (because I've got a solution for it) but I would like to know why it has happened in the first place. I've made use of a CPropertySheet control in one of my applications, it has two tabs (CPropertyPages) on it inherited from dialogues as CPropPage1 and CPropPage2 etc., pretty standard MFC via MSDN stuff. The sheet is constructed using AddPage (I think it's called that) not member variables in the CPropertySheet, everything works just perfectly, it constructs, shows and all the controls work great.

Now, when a button on the first property page is clicked, some extended processing needs to occur so I launch a worker thread and do some work. This works great too. Recently I added some options on the second property page and needed to make use of them during the extended processing thread on the first property page - still with me?

I wrote code (quickly guestimated) something like this:

void PropPage1::ButtonClick()
{
AfxBeginThread( Thread, this );
}

UINT Thread(LPVOID pParam)
{
CPropPage1 *caller = (CPropPage1 *)pParam;
CPropPage2 *options = NULL;
CPropertySheet *parent = NULL;

if(caller)
{
parent = (CPropertySheet *)GetParent();
if(parent) options = parent->GetPage(1);
... on and on - the rest doesn't matter.
}

return( preset_errorcode_from_somewhere );
}

Does that look OK? The reason I stop here is because at the "..." I get an Access Violation from CPropertySheet::GetPage(...) - the exact violation is from a CPtrArray I believe. No matter how many variations I do on this code, the same thing always happens. I might add that GetPageCount() correctly returns 2 indicating that there are two pages available.

The EXACT same code does not crash, if it is called from the CPropPage1::ButtonClick() handler instead of the worker thread. Now I'm aware that the code isn't exactly thread safe Wink | ;) but should it really be crashing? I aren't aware of the behind the scenes operation, but obviously something is crossing a boundary somewhere. Why? My solution was to pass pointers to the PropertyPages via a structure into the thread and that works fine. The problem would seem to be a fault with the way GetPage(...) works because all of the other CPropertyPage members appear to function perfectly.

Just curious to know if anyone has a potential explanation for this behaviour?
Jon.
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 
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 

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.