Solved

Thread in MFC

Posted on 2000-03-14
5
246 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
  • 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 147
Perl Awk Need Help 3 129
Best tools for Backup and restore of Wordpress site 6 57
tripleUp challenge 7 86
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

820 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