![]() |
| ||
| damages when executing console from MFC hi i created MFC dialog based application and in an event of a button i want to execute a C++ console application . i've tried severl functions such as shellexecute and create process ....but it executes it but then return the wrong answers .....where if i run the application console by itself ....it gave me the right calculations .... please i neeeed this so bad....my project is supposed to be delieverd in satureday MORNING(one day left) pleeeeeease thank u all |
| ||
| Re: damages when executing console from MFC What do you mean by 'it returns the wrong answers'? How are you returning data from the console application? |
| ||
| Re: damages when executing console from MFC by database from console to database from database to MFC |
| ||
| Re: damages when executing console from MFC That still isn't anywhere near enough information. What DB are you using? What commands are you using to access it? What software library are you using to interface with it? |
| ||
| Re: damages when executing console from MFC ok ... to be more clear ....what my program does is : 1- open acertain 2 files in 2 editboxes(through a browse buttons). 2-the content of the editboxes is saved in 2 files called file1, file2 . 3-then i press a button where it should execute a console applicatin to compare between file1 and file2 . the problem : if i did the last 3 steps its doesnot give the right answer all the time ...AND if i run the console application with the previous file1, file2 it doesnot give the right answer either. BUT if i run the console application elsewhere with the original names of the files chosen in the browse button , it gave me the right answer .. so i guess the problem in files or what???? HELP |
| ||
| Re: damages when executing console from MFC ok this is the code for the browse button: //**BROWSE DIALOG 1**//the same goes for file2. file1 and file2 are declared as: file1 = fopen("C:\\Program Files\\C++ Clone Detector\\file1.txt","w+"); //Create txt file for saving editbox contentand when i press the button : ShellExecute(this->m_hWnd,"open","C:\\Program Files\\C++ Clone Detector\\Debug\\proto1.exe","","", SW_HIDE ); and in the console application the file1 , file2 are declared : ifstream infile ("C:\\Program Files\\C++ Clone Detector\\file1.txt"); |
| ||
| Re: damages when executing console from MFC Ah, I think I know what is happening. The file stream is not required to keep the actual disk file up-to-date with the fstream's state at all times. It can wait until it is convenient to write data to the file. So it looks to me like there is a race condition occurring between the two applications to access the file data. You can force it to synchronize the disk file and the fstream's data buffer by using the flush function/manipulator, and for FILE*s use fflush(). So, when the button is clicked, the following should happen:
Call the ExecTheChildProc() when the button is pressed (or put the code in your button event method). The ProcessMessages() function is not defined by MFC. However, you can find it here. If you don't expect the child to take much time, you can skip the loop and everything and just say: return WaitForSingleObject( hChild, INFINITE ) == WAIT_OBJECT_0;That's a zero on the end of the WAIT_OBJECT_0 macro. Hope this helps. |
| All times are GMT -4. The time now is 8:55 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC