????? C++ .NET ?? Visual C++ 2005 ?? ????? ?? ???? FileCompare ?????? ?? ????? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 816189 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ??? ?? ??? ???? ????? ???? ?? ?? ??? ???? ??????? ???? ??? ?? ????? ?? ??? ?? ??????? ?? ????? ???? ????? ?? ????? ?? ?????? ?? ??????? ?? ????? ??, ????? ???? ???, ?????, ??????, ???, ?? ???? ????????? ?? ???? ???

?? ??????????? MS-DOS--?????? Fc.exe ?? ???? ?? ?????? ?? Microsoft Windows ?? MS-DOS ?? Microsoft ?? ??????? ??????? ?? ??? ?? ????? ?? ??? ????? ?? ??? ????? ???

????? ??? ?? ?? ???? ??? ???? ?? ?? ????-??-???? ?? ????? ???? ?? ?? ??? ????? ????? ??, ?? ?? ?? ?? ????? ?? ??? ?? ????? ???? ??? ??? ?? ????? ?? ?????? ???? ?? ????? ??? ?????? ?? ?????? ?? ??? ???? ??:
  • ??? ????? ?? ?? ????? ?? ??? ?????? ????? ???? ??, ????? ??????? ?? ????? ???? ??????
  • ??? ????? ?? ???? ????? ??????, ?? ??????? ????? ????

????? ?????

  1. Visual Studio .NET (2003) ?? Microsoft Visual Studio 2005 ??????? ?????
  2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
  3. ????? ????,????? C++ ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???????? ????????? (.NET)?? ???????????????. ????????? ?? ???FileCompare.

    ???:Visual Studio 2005, ??? ????? ????????? C++?? ???????????????? ???????? ????-????? ????, ?? ???? ???????? ??????????? ???????????????.
  4. ?????? Explorer ???, ???? ?????FileCompare?? ????? ????,add?? ????-????? ????, ?? ???? ????? ???? ??? ?????.
  5. ??????? ???? ??? ?????????? ????? ???, ????? ????????? ??? ?????? ???????????????. ??????????? ????? ???, ??????Form1?? ????-????? ????, ?? ???? ????????. Form1.h ????? ????????? ???? ???? ???
  6. Form1.h ????? ??? ????? ??? ?? ???????:
    #pragma once
    #using <mscorlib.dll>
    #using <system.windows.forms.dll>
    #using <system.dll>
    #using <system.drawing.dll>
    
    namespace Compare
    {
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Drawing;
    	using namespace System::IO;
    
    	public __gc class Form1 : public System::Windows::Forms::Form
    	{	
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    		}
      
    	protected:
    		void Dispose(Boolean disposing)
    		{
    			if (disposing && components)
    			{
    				components->Dispose();
    			}
    			__super::Dispose(disposing);
    		}
    	
    	private: System::Windows::Forms::TextBox *  textBox1;
    	private: System::Windows::Forms::TextBox *  textBox2;
    	private: System::Windows::Forms::Label *  label1;
    	private: System::Windows::Forms::Label *  label2;
    	private: System::Windows::Forms::Button *  Compare;
    
    
    	private:
    
    		System::ComponentModel::Container * components;
    
    		
    		void InitializeComponent(void)
    		{
    			this->textBox1 = new System::Windows::Forms::TextBox();
    			this->textBox2 = new System::Windows::Forms::TextBox();
    			this->label1 = new System::Windows::Forms::Label();
    			this->label2 = new System::Windows::Forms::Label();
    			this->Compare = new System::Windows::Forms::Button();
    			this->SuspendLayout();
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(32, 104);
    			this->textBox1->Name = S"textBox1";
    			this->textBox1->TabIndex = 0;
    			this->textBox1->Text = S"";
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(168, 104);
    			this->textBox2->Name = S"textBox2";
    			this->textBox2->TabIndex = 1;
    			this->textBox2->Text = S"";
    			// 
    			// label1
    			// 
    			this->label1->Location = System::Drawing::Point(32, 64);
    			this->label1->Name = S"label1";
    			this->label1->TabIndex = 2;
    			this->label1->Text = S"File1";
    			// 
    			// label2
    			// 
    			this->label2->Location = System::Drawing::Point(176, 64);
    			this->label2->Name = S"label2";
    			this->label2->TabIndex = 3;
    			this->label2->Text = S"File2";
    			// 
    			// Compare
    			// 
    			this->Compare->Location = System::Drawing::Point(96, 168);
    			this->Compare->Name = S"Compare";
    			this->Compare->TabIndex = 4;
    			this->Compare->Text = S"Compare";
    			this->Compare->Click += new System::EventHandler(this, button1_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
    			this->ClientSize = System::Drawing::Size(292, 273);
    			this->Controls->Add(this->Compare);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Name = S"Form1";
    			this->Text = S"Form1";
    			this->ResumeLayout(false);
    
    		}
    	private:
    		System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
    		{	 
    		}
    
    	};
    }
    ?? ??? ?? ?? ??? ????? ???????? ?? ??? ???? ??? ??? ??????? ????? ???

    ???:??????? ???? ?????? ?????? ??????? ?????? ?? ?????? ???? (/ clr:oldSyntax) ??? ??????????? ????? ??? ????? ?? ?????? ???? ?? ??? ????? C++ 2005? ????? ?? ??? ??????? ???? ?????? ?????? ??????? ?????? ????? C++ 2005 ???, ????? ????? ?? ???? ????:
    1. ????? ????,??????????? ????-????? ????, ?? ???? ???<projectname></projectname>???.

      ???:<projectname></projectname>????????? ?? ??? ?? ??? ?? ??????????? ???
    2. ??????? ??????????????? ????? ????-????? ????, ?? ???? ??????????.
    3. ?? ??? ???? ?? ??? ????? ??????????? ???? ?????? ??????, ?????? ???????? (/ clr:oldSyntax)???????????? ???? ?????? ?????????? ??? ??? ?????? Project, ????? ???????? ?????? ????-????? ????, ?? ???? ???OK.
    ??????? ???? ?????? ?? ???? ??? ???? ??????? ?? ??? ?????? ??????? ?????? ?? ???, ????? Microsoft ??? ???? ?? ????:
    /clr (??????? ???? ?????? Compilation)
    HTTP://msdn2.Microsoft.com/en-us/library/k8d11d4s.aspx
  7. ????? ????? ???? ?? ??? ??????Form1????:
    // This method accepts two strings that represent two files to 
    // compare. A return value of 0 indicates that the contents of the files
    // are the same. A return value of any other value indicates that the 
    // files are different.
    private:
    bool FileCompare(String *file1, String *file2)
    {
    	int file1byte;
    	int file2byte;
    	FileStream *fs1;
    	FileStream *fs2;
        
    	// Determine if the same file was referenced two times.
    	if (String::Equals(file1,file2))
    	{
    		// Return true to indicate that the files are the same.
    		return true;
    	}
    
            
    	// Open the two files.
    	try
    	{
    		fs1 = new FileStream(file1, FileMode::Open);
    		fs2 = new FileStream(file2, FileMode::Open);
    	
    			    
    		// Check the file sizes. If the sizes are different, the files 
    		// are different.
    		if (fs1->Length != fs2->Length)
    		{
    			// Close the file
    			fs1->Close();
    			fs2->Close();
    
    			// Return false to indicate files are different
    			return false;
    		}
    
    		// Read and compare a byte from each file until either a
    		// non-matching set of bytes is found or until the end of
    		// file1 is reached.
    		do 
    		{
    			// Read one byte from each file.
    			file1byte = fs1->ReadByte();
    			file2byte = fs2->ReadByte();
    		}
    		while ((file1byte == file2byte) && (file1byte != -1));
    
    		// Close the files.
    		fs1->Close();
    		fs2->Close();
    	}
    	
    	catch(Exception *ex)
    	{
    		if(fs1)
    		{
    			fs1->Close();
    		}
    		if(fs2)
    		{
    			fs2->Close();
    		}
    		throw ex;
    	}
    
    	// Return the success of the comparison. "file1byte" is 
    	// equal to "file2byte" at this point only if the files are 
    	// the same.
    	return ((file1byte - file2byte) == 0);
    }
    
    
  8. ??? ????? ??? ???????????? ????,?? ?????button1_Click??? ???? ???Form1????:
    try
    {
    	if (FileCompare(this->textBox1->Text, this->textBox2->Text))
    	{
    		MessageBox::Show("Files are equal.");				
    	}
    	else
    	{
    		MessageBox::Show("Files are not equal.");
    	}
    }
    catch(Exception *ex)
    {
    	MessageBox::Show(ex->Message);
    }
    
  9. ?????? Explorer ???, ???? ?????FileCompare?? ????? ????,add?? ????-????? ????, ?? ???? ????? ???? ??? ?????.
  10. ??????? ???? ??? ?????????? ????? ???, ????? ????C++ ?????? ???????????????. ??????????? ????? ???, ??????File_Compare?? ????-????? ????, ?? ???? ????????. File_Compare.cpp ????? ????????? ???? ???? ???
  11. File_Compare.cpp ????? ??? ????? ??? ?? ???????:
    #include "form1.h"
    
    #include <windows.h>
    #include <tchar.h>
    
    using namespace Compare;
  12. ????? ??????WinMainFile_Compare.cpp ????? ?? ??? ????? ????:
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    }
  13. ??? ????? ??? ???????WinMain?????? ?? ??? ???? ???.:
    System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;
    Application::Run(new Form1());
    return 0;
  14. ????? ???????

????? ?????

  1. ??? ????? ???????? ??? ????? ??????? ?? ??? ???? ?? ?????? ?????
  2. ????? ????,?? ????? ????.

??????

???? ??????? ?? ???, ????? Microsoft ?????? ??????? (MSDN) ??? ?????? ?? ????::
System.IO ????????
FileStream ???? ?? ????? ?????

???

???? ID: 816189 - ????? ???????: 05 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
??????: 
kbhowtomaster kbhowto kbio kbmt KB816189 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:816189

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com