Solved

Thread in MFC

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

14 Experts available now in Live!

Get 1:1 Help Now