View Single Post
Join Date: Apr 2008
Posts: 42
Reputation: lahom is an unknown quantity at this point 
Solved Threads: 0
lahom lahom is offline Offline
Light Poster

Re: damages when executing console from MFC

 
0
  #6
Jul 4th, 2008
ok
this is the code for the browse button:
  1. //**BROWSE DIALOG 1**//
  2. //******************************************************//
  3. char strFilter[] = "CPP Files (*.cpp)|*.cpp|All Files (*.*)|*.*||";
  4.  
  5. CFileDialog m_ldFile(TRUE, ".cpp", NULL, 0, strFilter);
  6.  
  7. if (m_ldFile.DoModal() == IDOK) //Start File dlg box
  8. {
  9. m_sFileName=m_ldFile.GetPathName(); //Get file name
  10.  
  11. FILE *fp=fopen(m_sFileName,"rb"); //Open file for reading
  12.  
  13. if( !fp )
  14. {
  15. DWORD dwError = GetLastError();
  16. CString sError;
  17. sError.Format("Open Error: %d, %d\n", errno, dwError);
  18. AfxMessageBox(sError);
  19. return;
  20. }
  21. // Get the file size
  22.  
  23. int nFileLong;
  24. {
  25. fseek(fp,0,SEEK_END); //Go to file end
  26. nFileLong=ftell(fp); //Get length
  27. fseek(fp,0,SEEK_SET); //Go to file start
  28. }
  29.  
  30.  
  31. char* sText = new char[nFileLong+1]; //reserve string space
  32.  
  33. int i=fread(sText,1,nFileLong,fp); //Read the characters
  34.  
  35. sText[i]=0; //Set string terminating null
  36.  
  37. fclose(fp); //Close file
  38.  
  39. // Make a copy
  40.  
  41. {
  42. // FILE *file1 = fopen("C:\\Program Files\\C++ Clone Detector\\file1.txt","w+"); //Create txt file for saving editbox content
  43.  
  44. if( !file1 )
  45. {
  46. DWORD dwError = GetLastError();
  47. CString sError;
  48. sError.Format("Copy Error: %d, %d\n", errno, dwError);
  49. AfxMessageBox(sError);
  50. }
  51. /*else
  52. {
  53. fwrite(sText,1,nFileLong,file1); //print the content of the editbox into the file
  54. fclose(file1); //Close file2
  55. }
  56. */
  57. }
  58.  
  59. m_EDIT1=sText; //Put text in Edit box's variable
  60.  
  61. fwrite(sText,1,nFileLong,file1); //print the content of the editbox into the file
  62. fclose(file1); //Close file2
  63.  
  64. delete [] sText;
  65.  
  66. UpdateData(FALSE); //Force data to go to Edit control
  67. }
the same goes for file2.
file1 and file2 are declared as:
  1. file1 = fopen("C:\\Program Files\\C++ Clone Detector\\file1.txt","w+"); //Create txt file for saving editbox content
  2. file2 = fopen("C:\\Program Files\\C++ Clone Detector\\file2.txt","w+"); //Create txt file for saving editbox content

and when i press the button :
  1. 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 :
  1. ifstream infile ("C:\\Program Files\\C++ Clone Detector\\file1.txt");
  2. ifstream infile2 ("C:\\Program Files\\C++ Clone Detector\\file2.txt");
Reply With Quote