Click here to Skip to main content
16,011,883 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC with message map versus old method Pin
Cambalindo20-Jun-03 7:17
Cambalindo20-Jun-03 7:17 
GeneralRe: MFC with message map versus old method Pin
Cambalindo20-Jun-03 7:19
Cambalindo20-Jun-03 7:19 
GeneralRe: MFC with message map versus old method Pin
John M. Drescher20-Jun-03 7:26
John M. Drescher20-Jun-03 7:26 
GeneralRe: MFC with message map versus old method Pin
John M. Drescher20-Jun-03 5:20
John M. Drescher20-Jun-03 5:20 
Generalhelp in C++ Pin
Mark J Jackson19-Jun-03 4:29
Mark J Jackson19-Jun-03 4:29 
GeneralRe: help in C++ Pin
AlexO19-Jun-03 4:38
AlexO19-Jun-03 4:38 
GeneralRe: help in C++ Pin
David Crow19-Jun-03 10:19
David Crow19-Jun-03 10:19 
GeneralThread Pin
Gandilf19-Jun-03 4:09
Gandilf19-Jun-03 4:09 
Hi everyone,

I have a little question about thread. I have read the faq and managed to program threads but now I'm facing a newbie challenge : I need to access to my dialog controls and the Document. I copy this code from this forum to access the Document from anywhere in my program.

//Declaration
static CTestSDIDoc * GetDoc();

//Implementation
CTestSDIDoc * CTestSDIDoc::GetDoc()
{
CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);
return (CTestSDIDoc *) pFrame->GetActiveDocument();
}

In my dialog (my own progress window with static text, a progress bar, 6 bitmaps and an OK button), I want to show a green check mark when a process has done is job. The process is created with CreateProcess method. The CreateProcess is writed in the TreadFunc of my dialog class. Before calling createprocess method, I must do some initialization in the Document so I must do this :

metprof *metProfPtr = static_cast<metprof *="">(pvParam);
CTestSDIDoc *pDoc = static_cast<ctestsdidoc *="">(pvParam);

pDoc=CTestSDIDoc::GetDoc();

The bold text code works everywhere except in the TreadFunc method (I've got an assertion when running in debug mode). I want to know what Am I doing wrong ?

Here my complete ThreadFunc function:

UINT metprof::ThreadFunc(LPVOID pvParam)
{


metprof *metProfPtr = static_cast<metprof *="">(pvParam);
CTestSDIDoc *pDoc = static_cast<ctestsdidoc *="">(pvParam);


CString workingDirectory,strTemp,appArguments,strTemp2;


pDoc=CTestSDIDoc::GetDoc();
TRACE("vis: %d\n",pDoc->m_VIS);


workingDirectory=pDoc->m_modulesDirectory;
workingDirectory.Insert(workingDirectory.GetLength(),"ATMOSPHERIC\\\\");
pDoc->m_SL_COND=1;
appArguments=pDoc->m_dosPrompt;
pDoc->createMetDataFile();
pDoc->createMetProfInputFiles();

STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;


memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));


siStartupInfo.cb = sizeof(siStartupInfo);
strTemp2=pDoc->m_binDirectory;
strTemp2.Replace("\\\\","\\");
strTemp2.Delete(strTemp2.GetLength()-1,1);
strTemp.Format(" /c \"metprof.exe < metprof.rep -L -P \"%s\"\"",strTemp2);
appArguments.Insert(appArguments.GetLength(),strTemp);

char *str = appArguments.GetBuffer(appArguments.GetLength());

if(CreateProcess(NULL, // Application name
str,//"cmd /c \"metprof.exe < metprof.rep -L\"",// Application arguments
0,
0,
FALSE,
CREATE_NO_WINDOW,
0,
workingDirectory,//"C:\\Program Files\\Irblempkg\\IRBLEM4.1\\modules\\atmospheric\\", // Working directory
&siStartupInfo,
&piProcessInfo)){}

::WaitForSingleObject(piProcessInfo.hProcess,INFINITE);
metProfPtr->GetDlgItem(IDC_CHECKMETEO)->ShowWindow(TRUE);
pDoc->moveMetProfOutputFiles();

return 0;
}

I think I'm missing something with my code but I don't know what.

Thanks for your help,

Rene
GeneralRe: Thread Pin
AlexO19-Jun-03 4:18
AlexO19-Jun-03 4:18 
GeneralRe: Thread Pin
AlexO19-Jun-03 4:22
AlexO19-Jun-03 4:22 
GeneralRe: Thread Pin
Gandilf19-Jun-03 4:48
Gandilf19-Jun-03 4:48 
GeneralRe: Thread Pin
AlexO19-Jun-03 5:35
AlexO19-Jun-03 5:35 
GeneralRe: Thread Pin
Ryan Binns19-Jun-03 4:22
Ryan Binns19-Jun-03 4:22 
GeneralRe: Thread Pin
Jonathan Craig19-Jun-03 5:09
Jonathan Craig19-Jun-03 5:09 
GeneralRe: Thread Pin
Jonathan Craig20-Jun-03 3:37
Jonathan Craig20-Jun-03 3:37 
GeneralRe: Thread Pin
Brian Delahunty19-Jun-03 7:57
Brian Delahunty19-Jun-03 7:57 
GeneralRe: Thread Pin
David Crow19-Jun-03 10:22
David Crow19-Jun-03 10:22 
GeneralCSpinButtonCtrl Pin
#realJSOP19-Jun-03 3:54
professional#realJSOP19-Jun-03 3:54 
GeneralRe: CSpinButtonCtrl Pin
David Chamberlain19-Jun-03 4:05
David Chamberlain19-Jun-03 4:05 
GeneralRe: CSpinButtonCtrl Pin
#realJSOP19-Jun-03 4:09
professional#realJSOP19-Jun-03 4:09 
GeneralRe: CSpinButtonCtrl Pin
David Chamberlain19-Jun-03 4:19
David Chamberlain19-Jun-03 4:19 
GeneralRe: CSpinButtonCtrl Pin
#realJSOP19-Jun-03 4:35
professional#realJSOP19-Jun-03 4:35 
GeneralRe: CSpinButtonCtrl Pin
David Chamberlain19-Jun-03 4:56
David Chamberlain19-Jun-03 4:56 
GeneralPopup Menu Pin
modular19-Jun-03 3:20
modular19-Jun-03 3:20 
GeneralRe: Popup Menu Pin
AlexO19-Jun-03 3:34
AlexO19-Jun-03 3:34 

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.