Click here to Skip to main content
16,015,296 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Change Icon of exe Pin
the_augy13-Sep-04 16:21
the_augy13-Sep-04 16:21 
GeneralRe: Change Icon of exe Pin
Arsalan Malik13-Sep-04 18:49
Arsalan Malik13-Sep-04 18:49 
GeneralRe: Change Icon of exe Pin
Ryan Binns13-Sep-04 20:50
Ryan Binns13-Sep-04 20:50 
GeneralLocalization of negative numbers Pin
PJ Arends13-Sep-04 13:15
professionalPJ Arends13-Sep-04 13:15 
GeneralRe: Localization of negative numbers Pin
cmk13-Sep-04 23:42
cmk13-Sep-04 23:42 
GeneralRe: Localization of negative numbers Pin
PJ Arends14-Sep-04 6:53
professionalPJ Arends14-Sep-04 6:53 
GeneralMFC threading issue... Pin
the_augy13-Sep-04 12:59
the_augy13-Sep-04 12:59 
GeneralUpdate to my question (a doozy!) Pin
the_augy13-Sep-04 14:31
the_augy13-Sep-04 14:31 
I've stepped through my code very carefully, and I'll describe exactly what happens.

Here is the high level of the code that I'm debugging. BeginInterfacing() is the function that creates the child thread which plays the animated gif file, and EndInterfacing destroys it. This code is all happening within an event handler from a dialog.

<br />
	m_pParent->BeginInterfacing();<br />
	m_pID->GetWindowText(m_pParent->m_strName);<br />
	m_pPass->GetWindowText(m_pParent->m_strPass);<br />
	m_pParent->m_strName.Remove(' ');<br />
<br />
	m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName);<br />
<br />
	if (!m_pParent->m_pSub->VerifyPassword(m_pParent->m_strPass))<br />
	{<br />
		m_pParent->EndInterfacing();<br />
		MessageBox("Invalid Password", "Invalid Password", MB_OK|MB_ICONSTOP);<br />
		delete m_pParent->m_pSub;<br />
		m_pParent->m_pSub = NULL;<br />
		return -1;<br />
	}<br />
	m_pParent->EndInterfacing();<br />


If I step over BeginInterfacing, no dialog box comes up and none of my breakpoints are triggered (I have them in Run(), EndInterfacing(), and DoModal() of the dialog box that the child thread creates). I can step through until the line
m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName);<br />


When I try to F10 over this line, my breakpoint in Run() of my CWinThread class is triggered:

int CInterface::Run()<br />
{<br />
	m_pD.DoModal();<br />
	if (m_pParent)<br />
		m_pParent->PostMessage(WM_KILLINTERFACING);<br />
<br />
	return 0;<br />
}<br />


m_pD is the dialog that will loop the gif file.
Next, I step into DoModal....

	if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))<br />
	{<br />
		::EnableWindow(hWndParent, FALSE);<br />
		bEnableParent = TRUE;<br />
	}<br />
<br />
	TRY<br />
	{<br />
		// create modeless dialog<br />
		AfxHookWindowCreate(this);<br />


At the line ::EnableWindow(hWndParent, FALSE), execution seems to switch back to where it left off in the top level function, and
m_pParent->m_pSub = new CSubscriber(m_pParent->m_strName);
gets executed next. In fact, execution never returns to where it left off in DoModal() (or any other part of the child thread) until much later, where it goes right back to bEnableParent = TRUE and then creates the modal dialog box normally, but of course it does this at a time I can't pin down and so I have this modal dialog box looping a gif without any way to stop it, so I have to CTRL+ALT+DEL the program, or stop debugging.
The thing I would really like to figure out is why the thread stopped where it did (in the middle of DoModal) and then decided to start back up again when the main thread isn't doing any processing.

Here are Begin and End Interfacing, just for completeness:
void ClassNameProtected::BeginInterfacing()<br />
{<br />
	if (m_bBI)<br />
	{<br />
		return;<br />
	}<br />
<br />
	if(!m_pI)<br />
	{<br />
		m_pI = new CInterface(this);<br />
		m_pI->CreateThread();<br />
		m_pI->SetThreadPriority(THREAD_PRIORITY_HIGHEST);<br />
	}<br />
	<br />
	m_bBI = TRUE;<br />
}<br />
<br />
void ClassNameProtected::EndInterfacing()<br />
{<br />
	if (!m_bBI) return;<br />
<br />
	m_pI->KillInterface();<br />
	// we don't need to delete or NULLify m_pI<br />
	// because our KillInterface() function gets called<br />
	// by the thread, and it takes care of all that.<br />
<br />
	m_bBI = FALSE;<br />
}<br />
<br />
void CInterface::KillInterface()<br />
{<br />
	if (m_pD.m_hWnd)<br />
	{<br />
		m_pD.PostMessage(WM_COMMAND, IDCANCEL);<br />
	}<br />
}<br />
<br />


of course, KillInterface() never works because the DoModal() code has stopped before actually creating a window, and so the PostMessage never goes through. Thus, DoModal() never stops, so the Run() function never gets past the DoModal() statement, so the WM_KILLINTERFACING message never gets sent to the ClassNameProtected message pump. ClassNameProtected has a handler which attempts to stop the child thread from processing and then delete the CWinThread object and set m_pI to NULL. That never happens, so my child thread's dialog is now modally looping a gif and my program can't get out.

*exhales*

So, I'll ask again...

any ideas?
GeneralAnother string question....I think Pin
Tom Wright13-Sep-04 12:29
Tom Wright13-Sep-04 12:29 
GeneralRe: Another string question....I think Pin
Arsalan Malik13-Sep-04 18:36
Arsalan Malik13-Sep-04 18:36 
Generaldelegating events from child to parent Pin
prateekkathuria13-Sep-04 11:10
prateekkathuria13-Sep-04 11:10 
GeneralHeight of Text Pin
Joel Holdsworth13-Sep-04 10:40
Joel Holdsworth13-Sep-04 10:40 
GeneralRe: Height of Text Pin
Joel Holdsworth13-Sep-04 11:14
Joel Holdsworth13-Sep-04 11:14 
GeneralRe: Height of Text Pin
cmk13-Sep-04 13:00
cmk13-Sep-04 13:00 
GeneralCopy Constructor Pin
Prudhvi Raju13-Sep-04 10:10
Prudhvi Raju13-Sep-04 10:10 
GeneralRe: Copy Constructor Pin
act_x13-Sep-04 10:25
act_x13-Sep-04 10:25 
GeneralRe: Copy Constructor Pin
BlackDice13-Sep-04 11:58
BlackDice13-Sep-04 11:58 
GeneralRe: Copy Constructor Pin
Anonymous13-Sep-04 12:14
Anonymous13-Sep-04 12:14 
QuestionHow to idintify a DLL whether it is a normal dll or it is a COM DLL Pin
Prudhvi Raju13-Sep-04 9:57
Prudhvi Raju13-Sep-04 9:57 
AnswerRe: How to idintify a DLL whether it is a normal dll or it is a COM DLL Pin
Anonymous13-Sep-04 15:14
Anonymous13-Sep-04 15:14 
GeneralDoc View architecture Pin
act_x13-Sep-04 9:41
act_x13-Sep-04 9:41 
GeneralRe: Doc View architecture Pin
Joel Holdsworth13-Sep-04 10:48
Joel Holdsworth13-Sep-04 10:48 
GeneralRe: Doc View architecture Pin
BlackDice13-Sep-04 12:02
BlackDice13-Sep-04 12:02 
GeneralC/C++ Scripters Wanted For New Games Company Pin
KingsZone13-Sep-04 8:32
sussKingsZone13-Sep-04 8:32 
GeneralRe: C/C++ Scripters Wanted For New Games Company Pin
Michael Dunn13-Sep-04 8:54
sitebuilderMichael Dunn13-Sep-04 8:54 

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.