Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Thread in MFC

Posted on 2000-03-14
5
Medium Priority
?
250 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:
Vinayak Kumbar earned 150 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

885 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