Click here to Skip to main content
15,921,793 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pop of the tops Pin
Tomasz Sowinski12-Aug-02 0:45
Tomasz Sowinski12-Aug-02 0:45 
GeneralRe: pop of the tops Pin
Zizilamoroso12-Aug-02 1:02
Zizilamoroso12-Aug-02 1:02 
GeneralRe: pop of the tops Pin
Tomasz Sowinski12-Aug-02 1:09
Tomasz Sowinski12-Aug-02 1:09 
GeneralRe: pop of the tops Pin
Zizilamoroso12-Aug-02 1:20
Zizilamoroso12-Aug-02 1:20 
GeneralRe: pop of the tops Pin
Zizilamoroso12-Aug-02 1:26
Zizilamoroso12-Aug-02 1:26 
GeneralSDK version of LISTBOX Pin
zecodela12-Aug-02 0:21
zecodela12-Aug-02 0:21 
GeneralRe: SDK version of LISTBOX Pin
Tomasz Sowinski12-Aug-02 0:28
Tomasz Sowinski12-Aug-02 0:28 
GeneralPassing data to thread Pin
s_k11-Aug-02 23:01
s_k11-Aug-02 23:01 
Hi !
I have following problem.
I use threads to send data to another application (WM_COPYDATA), because I dont want to wait for SendMessage function finishes.
So, I have sendNotify function, that starts threads and passes some user-defined data to it. This functions looks like this:

<br />
void CHinfoServerApp::sendNotify(NotifyCode nCode, LPVOID data)<br />
{<br />
	.<br />
	.<br />
	.<br />
case NC_SCREENLOG:<br />
	{<br />
		ScreenLogData slData = *((ScreenLogData*) data);	// TAKES SEDOND PARAMETER AND CASTS IT TO STRUCT<br />
		COPYDATASTRUCT cpd;<br />
		SendNotifyThreadInfo sntInfo;				// USER-DEFINED STRUCTURE SENT TO THREAD<br />
		cpd.dwData = NC_SCREENLOG;<br />
		cpd.cbData = sizeof(slData);<br />
		cpd.lpData = (void*)&slData;<br />
		sntInfo.cpd = cpd;<br />
		sntInfo.hDestWnd = (HWND)hGUIManagerWindow;		// HWND OF DESTINATION WINDOW<br />
		AfxBeginThread(sendNotifyThread, (void*)&sntInfo);<br />
		break;<br />
	}<br />
	.<br />
	.<br />
}<br />


This function is used as follows:
	.<br />
	.<br />
ScreenLogData slData;<br />
// JUST LOAD SOME STRING<br />
LoadString(((CMainFrame*)m_pMainWnd)->getResHandle(), IDS_SERVICE_LOG_INIT, slData.text, 2 * MY_MAX_PATH);<br />
sendNotify(NC_SCREENLOG, (void*)&slData);<br />
	.<br />
	.<br />


The thread function looks like this:
<br />
UINT sendNotifyThread(LPVOID lParam)<br />
{<br />
	SendNotifyThreadInfo sntInfo = *((SendNotifyThreadInfo*)(lParam));	// THIS LINE IS WRONG  <br />
	COPYDATASTRUCT cpd = sntInfo.cpd;	<br />
	<br />
	::SendMessage((HWND)(sntInfo.hDestWnd), WM_COPYDATA, (WPARAM) AfxGetApp()->m_pMainWnd->GetSafeHwnd(), (LPARAM)&cpd);<br />
	return 0;<br />
}<br />


ScreenLogData and SendNorifyThreadInfo structures are defined as follows:
<br />
typedef struct {<br />
	char text[2 * MY_MAX_PATH];<br />
} ScreenLogData;<br />
<br />
typedef struct {<br />
	COPYDATASTRUCT cpd;<br />
	HWND hDestWnd;<br />
} SendNotifyThreadInfo;<br />


In the thread function, I highlighted the problem line. On this line appears error - something with memory access. And I want to know why. I think that it is something with that the pointer in sendNotify function is created on stack and in the thread function it is no longer valid. Am I right ? And how can I do this safely ???
Any suggestion helps a lot.

Celebrate Mr. Cesilko!
GeneralRe: Passing data to thread Pin
Daniel Lohmann11-Aug-02 23:15
Daniel Lohmann11-Aug-02 23:15 
GeneralRe: Passing data to thread Pin
s_k11-Aug-02 23:36
s_k11-Aug-02 23:36 
GeneralRe: Passing data to thread Pin
Tomasz Sowinski11-Aug-02 23:40
Tomasz Sowinski11-Aug-02 23:40 
GeneralRe: Passing data to thread Pin
Daniel Lohmann12-Aug-02 2:24
Daniel Lohmann12-Aug-02 2:24 
Generalthreads and wotnots... Pin
l a u r e n11-Aug-02 22:57
l a u r e n11-Aug-02 22:57 
GeneralRe: threads and wotnots... Pin
Tomasz Sowinski11-Aug-02 23:04
Tomasz Sowinski11-Aug-02 23:04 
GeneralRe: threads and wotnots... Pin
l a u r e n12-Aug-02 4:19
l a u r e n12-Aug-02 4:19 
GeneralRe: threads and wotnots... Pin
Shog912-Aug-02 13:50
sitebuilderShog912-Aug-02 13:50 
QuestionHow to display graphic image in a dialog box? Pin
Solero11-Aug-02 22:45
Solero11-Aug-02 22:45 
AnswerRe: How to display graphic image in a dialog box? Pin
Tomasz Sowinski11-Aug-02 22:53
Tomasz Sowinski11-Aug-02 22:53 
QuestionCFileDialog interferes later used fopen? Pin
Janine11-Aug-02 21:11
Janine11-Aug-02 21:11 
AnswerRe: CFileDialog interferes later used fopen? Pin
Tomasz Sowinski11-Aug-02 23:17
Tomasz Sowinski11-Aug-02 23:17 
AnswerRe: CFileDialog interferes later used fopen? Pin
Anonymous11-Aug-02 23:56
Anonymous11-Aug-02 23:56 
GeneralRe: CFileDialog interferes later used fopen? Pin
Janine12-Aug-02 0:04
Janine12-Aug-02 0:04 
GeneralKey Stokes Pin
Kristian3311-Aug-02 21:06
Kristian3311-Aug-02 21:06 
GeneralRe: Key Stokes Pin
567890123411-Aug-02 21:16
567890123411-Aug-02 21:16 
GeneralRe: Key Stokes Pin
Kristian3311-Aug-02 21:58
Kristian3311-Aug-02 21:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.