Solved

Thread in MFC

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now