Solved

Thread in MFC

Posted on 2000-03-14
5
248 Views
Last Modified: 2013-11-20
I have a simple MFC application which holds one dialog with several controls.
I created a thread and with function wich applies to one of the dialog controls. When I run the program I immidiatly have Assertion Failure.
Here is the code:


static UINT Recieve(LPVOID d)
{
   MainDlg& dobj = *(MainDlg*)d;
   cMessage m;
   int i=1;
   int Status;
   CString tmp = ((char)m.mDestination);
//here it fails:
dobj.m_MessageCntrl.SetWindowText(tmp);
      }
      return 0;
}

Could anybody solve this problem for me
Thanks
0
Comment
Question by:juliam64
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
VinExpert earned 50 total points
ID: 2615677
Hi,

How d is passed?
Is it done as
LPVOID d;
d = &urdialog;

Then access as
MainDlg *dobj = (MainDlg*)d;

Or else have the CDialog's global pointer as
CDialog *g_dlg = NULL;

Then initialise it to the dialog as something like in InitDialog
g_dlg = this;

Then U can straight away use that pointer in the thread.

Try it out.

VinExpert
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2615695


 

0
 
LVL 5

Expert Comment

by:Wyn
ID: 2615704
Why by reference not by pointer?
What is m.mDestination ?

Try changing it to (char*)(m.mDestination)?

0
 

Author Comment

by:juliam64
ID: 2615754
The problem was that I was referrin a dialog in it's constructor, before it was created, it stroke me when I saw
InitDialog,
Thanks
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2615782
I see.
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question