C# to C++

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Map_Maker_Worker
{
 /// <summary>
 /// Dialog for a useless application that runs a checksum on multiple maps.
 /// </summary>
 public class frmSigner : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button btnSelectMaps;
  private System.Windows.Forms.Button btnRemove;
  private System.Windows.Forms.Button btnSign;
  private System.Windows.Forms.ListBox lbx;
  private System.Windows.Forms.OpenFileDialog ofd;
  private System.Windows.Forms.Label lblAuthor;
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public frmSigner()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();
   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSigner));
   this.btnSelectMaps = new System.Windows.Forms.Button();
   this.btnRemove = new System.Windows.Forms.Button();
   this.btnSign = new System.Windows.Forms.Button();
   this.lbx = new System.Windows.Forms.ListBox();
   this.ofd = new System.Windows.Forms.OpenFileDialog();
   this.lblAuthor = new System.Windows.Forms.Label();
   this.SuspendLayout();
   //
   // btnSelectMaps
   //
   this.btnSelectMaps.BackColor = System.Drawing.Color.Transparent;
   this.btnSelectMaps.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
   this.btnSelectMaps.ForeColor = System.Drawing.Color.White;
   this.btnSelectMaps.Location = new System.Drawing.Point(48, 62);
   this.btnSelectMaps.Name = "btnSelectMaps";
   this.btnSelectMaps.Size = new System.Drawing.Size(96, 24);
   this.btnSelectMaps.TabIndex = 0;
   this.btnSelectMaps.Text = "Add Maps";
   this.btnSelectMaps.Click += new System.EventHandler(this.btnSelectMaps_Click);
   //
   // btnRemove
   //
   this.btnRemove.BackColor = System.Drawing.Color.Transparent;
   this.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
   this.btnRemove.ForeColor = System.Drawing.Color.White;
   this.btnRemove.Location = new System.Drawing.Point(48, 88);
   this.btnRemove.Name = "btnRemove";
   this.btnRemove.Size = new System.Drawing.Size(96, 24);
   this.btnRemove.TabIndex = 1;
   this.btnRemove.Text = "Remove Maps";
   this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
   //
   // btnSign
   //
   this.btnSign.BackColor = System.Drawing.Color.Transparent;
   this.btnSign.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
   this.btnSign.ForeColor = System.Drawing.Color.White;
   this.btnSign.Location = new System.Drawing.Point(496, 88);
   this.btnSign.Name = "btnSign";
   this.btnSign.Size = new System.Drawing.Size(96, 24);
   this.btnSign.TabIndex = 2;
   this.btnSign.Text = "Sign Maps";
   this.btnSign.Click += new System.EventHandler(this.btnSign_Click);
   //
   // lbx
   //
   this.lbx.BackColor = System.Drawing.Color.Black;
   this.lbx.BorderStyle = System.Windows.Forms.BorderStyle.None;
   this.lbx.ForeColor = System.Drawing.Color.White;
   this.lbx.HorizontalScrollbar = true;
   this.lbx.Location = new System.Drawing.Point(152, 328);
   this.lbx.Name = "lbx";
   this.lbx.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
   this.lbx.Size = new System.Drawing.Size(328, 117);
   this.lbx.TabIndex = 3;
   //
   // lblAuthor
   //
   this.lblAuthor.BackColor = System.Drawing.Color.Transparent;
   this.lblAuthor.ForeColor = System.Drawing.Color.PaleTurquoise;
   this.lblAuthor.Location = new System.Drawing.Point(506, 426);
   this.lblAuthor.Name = "lblAuthor";
   this.lblAuthor.Size = new System.Drawing.Size(88, 16);
   this.lblAuthor.TabIndex = 4;
   this.lblAuthor.Text = "The Swamp Fox";
   //
   // frmSigner
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
   this.ClientSize = new System.Drawing.Size(632, 446);
   this.Controls.Add(this.lblAuthor);
   this.Controls.Add(this.lbx);
   this.Controls.Add(this.btnSign);
   this.Controls.Add(this.btnRemove);
   this.Controls.Add(this.btnSelectMaps);
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
   this.MaximizeBox = false;
   this.Name = "frmSigner";
   this.Text = "Plz Make My Maps Work!!1";
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new frmSigner());
  }

  private void btnSelectMaps_Click(object sender, System.EventArgs e)
  {
   ofd.Title = "Select map(s).";
   ofd.Filter = "Halo 2 Map File (*.map)|*.map|All Files (*.*)|*.*";
   ofd.FileName = ".map";
   ofd.Multiselect = true;

   if(ofd.ShowDialog() == DialogResult.OK)
    lbx.Items.AddRange(ofd.FileNames);
  }

  private void btnRemove_Click(object sender, System.EventArgs e)
  {
   int nCount = lbx.Items.Count;
   for(int nIndex = nCount - 1; nIndex >= 0; nIndex--)
    if(lbx.SelectedIndices.Contains(nIndex))
     lbx.Items.RemoveAt(nIndex);
  }

  private void btnSign_Click(object sender, System.EventArgs e)
  {
   System.DateTime dtStart = System.DateTime.Now;
   foreach(string sMap in lbx.Items)
   {
    System.IO.FileStream fs = new System.IO.FileStream(sMap, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read);
    if(fs.Length % 4 != 0)
    {
     MessageBox.Show("The map " + sMap + " is not even bounded to four...You really screwed something up, and it will not be signed.", "Map Signer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     continue;
    }
    int nChecksum = 0;
    System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
    br.BaseStream.Position = 0x800;
    int nEndOfFile = (int)fs.Length;
    for(int x = 0x800; x < nEndOfFile; x += 4)
     nChecksum ^= br.ReadInt32();
    fs.Position = 0x2d0;
    fs.Write(BitConverter.GetBytes(nChecksum), 0, 4);
    br.Close();
    fs.Close();
    fs = null;
   }
   MessageBox.Show("Complete!\nStart Time: " + dtStart.ToString() + "\nFinish Time: " + System.DateTime.Now.ToString(), "Map Signer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  }
 }
}




Answer this question

C# to C++

  • Jeff Wharton

    My test for compilablity was on a test machine with Beta 2 (got to update that...).

    Anyway - we've fixed one minor bug ("DateTime::Now.ToString") and implemented a work-around to the difficulty that the VC++ compiler has in recognizing "DialogResult::OK" (for some reason VC++ needs to have it fully qualified, even though all other .NET compilers recognize it).

    However, we deliberately leave the parameterized Dispose method - we convert parameterless Dispose methods, but you'll have to decide how you want your parameterized Dispose method to look in C++.  Note that the Beta 2 compiler allows Dispose(Boolean) - that's why it compiled for me.  Once you change this, the code will compile.

    Here's the updated code:

    using namespace System;
    using namespace System::Drawing;
    using namespace System::Collections;
    using namespace System::ComponentModel;
    using namespace System::Windows::Forms;
    using namespace System::Data;

    namespace Map_Maker_Worker
    {
     /// <summary>
     /// Dialog for a useless application that runs a checksum on multiple maps.
     /// </summary>
     public ref class frmSigner : System::Windows::Forms::Form
     {
      private:
      System::Windows::Forms::Button ^btnSelectMaps;
      System::Windows::Forms::Button ^btnRemove;
      System::Windows::Forms::Button ^btnSign;
      System::Windows::Forms::ListBox ^lbx;
      System::Windows::Forms::OpenFileDialog ^ofd;
      System::Windows::Forms::Label ^lblAuthor;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      System::ComponentModel::Container ^components;

      public:
      frmSigner()
      {
       //
       // Required for Windows Form Designer support
       //
       InitializeComponent();
       //
       // TODO: Add any constructor code after InitializeComponent call
       //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      private protected:
      virtual void Dispose(Boolean disposing) override
      {
       if(disposing)
       {
     if (components != nullptr)
     {
      delete components;
     }
       }
       __super::Dispose(disposing);
      }

      #pragma region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private:
      void InitializeComponent()
      {
       System::Resources::ResourceManager ^resources = gcnew System::Resources::ResourceManager(frmSigner::typeid);
       this->btnSelectMaps = gcnew System::Windows::Forms::Button();
       this->btnRemove = gcnew System::Windows::Forms::Button();
       this->btnSign = gcnew System::Windows::Forms::Button();
       this->lbx = gcnew System::Windows::Forms::ListBox();
       this->ofd = gcnew System::Windows::Forms::OpenFileDialog();
       this->lblAuthor = gcnew System::Windows::Forms::Label();
       this->SuspendLayout();
       //
       // btnSelectMaps
       //
       this->btnSelectMaps->BackColor = System::Drawing::Color::Transparent;
       this->btnSelectMaps->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnSelectMaps->ForeColor = System::Drawing::Color::White;
       this->btnSelectMaps->Location = System::Drawing::Point(48, 62);
       this->btnSelectMaps->Name = "btnSelectMaps";
       this->btnSelectMaps->Size = System::Drawing::Size(96, 24);
       this->btnSelectMaps->TabIndex = 0;
       this->btnSelectMaps->Text = "Add Maps";
       this->btnSelectMaps->Click += gcnew System::EventHandler(this, &frmSigner::btnSelectMaps_Click);
       //
       // btnRemove
       //
       this->btnRemove->BackColor = System::Drawing::Color::Transparent;
       this->btnRemove->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnRemove->ForeColor = System::Drawing::Color::White;
       this->btnRemove->Location = System::Drawing::Point(48, 88);
       this->btnRemove->Name = "btnRemove";
       this->btnRemove->Size = System::Drawing::Size(96, 24);
       this->btnRemove->TabIndex = 1;
       this->btnRemove->Text = "Remove Maps";
       this->btnRemove->Click += gcnew System::EventHandler(this, &frmSigner::btnRemove_Click);
       //
       // btnSign
       //
       this->btnSign->BackColor = System::Drawing::Color::Transparent;
       this->btnSign->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnSign->ForeColor = System::Drawing::Color::White;
       this->btnSign->Location = System::Drawing::Point(496, 88);
       this->btnSign->Name = "btnSign";
       this->btnSign->Size = System::Drawing::Size(96, 24);
       this->btnSign->TabIndex = 2;
       this->btnSign->Text = "Sign Maps";
       this->btnSign->Click += gcnew System::EventHandler(this, &frmSigner::btnSign_Click);
       //
       // lbx
       //
       this->lbx->BackColor = System::Drawing::Color::Black;
       this->lbx->BorderStyle = System::Windows::Forms::BorderStyle::None;
       this->lbx->ForeColor = System::Drawing::Color::White;
       this->lbx->HorizontalScrollbar = true;
       this->lbx->Location = System::Drawing::Point(152, 328);
       this->lbx->Name = "lbx";
       this->lbx->SelectionMode = System::Windows::Forms::SelectionMode::MultiExtended;
       this->lbx->Size = System::Drawing::Size(328, 117);
       this->lbx->TabIndex = 3;
       //
       // lblAuthor
       //
       this->lblAuthor->BackColor = System::Drawing::Color::Transparent;
       this->lblAuthor->ForeColor = System::Drawing::Color::PaleTurquoise;
       this->lblAuthor->Location = System::Drawing::Point(506, 426);
       this->lblAuthor->Name = "lblAuthor";
       this->lblAuthor->Size = System::Drawing::Size(88, 16);
       this->lblAuthor->TabIndex = 4;
       this->lblAuthor->Text = "The Swamp Fox";
       //
       // frmSigner
       //
       this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
       this->BackgroundImage = (safe_cast<System::Drawing::Image^>(resources->GetObject("$this.BackgroundImage")));
       this->ClientSize = System::Drawing::Size(632, 446);
       this->Controls->Add(this->lblAuthor);
       this->Controls->Add(this->lbx);
       this->Controls->Add(this->btnSign);
       this->Controls->Add(this->btnRemove);
       this->Controls->Add(this->btnSelectMaps);
       this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
       this->MaximizeBox = false;
       this->Name = "frmSigner";
       this->Text = "Plz Make My Maps Work!!1";
       this->ResumeLayout(false);

      }
      #pragma endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application::Run(gcnew frmSigner());
      }

      void btnSelectMaps_Click(Object ^sender, System::EventArgs ^e)
      {
       ofd->Title = "Select map(s).";
       ofd->Filter = "Halo 2 Map File (*.map)|*.map|All Files (*.*)|*.*";
       ofd->FileName = ".map";
       ofd->Multiselect = true;

       if(ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK)
     lbx->Items->AddRange(ofd->FileNames);
      }

      void btnRemove_Click(Object ^sender, System::EventArgs ^e)
      {
       int nCount = lbx->Items->Count;
       for(int nIndex = nCount - 1; nIndex >= 0; nIndex--)
     if(lbx->SelectedIndices->Contains(nIndex))
      lbx->Items->RemoveAt(nIndex);
      }

      void btnSign_Click(Object ^sender, System::EventArgs ^e)
      {
       System::DateTime dtStart = System::DateTime::Now;
       for each(String ^sMap in lbx->Items)
       {
     System::IO::FileStream ^fs = gcnew System::IO::FileStream(sMap, System::IO::FileMode::Open, System::IO::FileAccess::ReadWrite, System::IO::FileShare::Read);
     if(fs->Length % 4 != 0)
     {
      MessageBox::Show("The map " + sMap + " is not even bounded to four...You really screwed something up, and it will not be signed.", "Map Signer", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
      continue;
     }
     int nChecksum = 0;
     System::IO::BinaryReader ^br = gcnew System::IO::BinaryReader(fs);
     br->BaseStream->Position = 0x800;
     int nEndOfFile = safe_cast<int>(fs->Length);
     for(int x = 0x800; x < nEndOfFile; x += 4)
      nChecksum ^= br->ReadInt32();
     fs->Position = 0x2d0;
     fs->Write(BitConverter::GetBytes(nChecksum), 0, 4);
     br->Close();
     fs->Close();
     fs = nullptr;
       }
       MessageBox::Show("Complete!\nStart Time: " + dtStart.ToString() + "\nFinish Time: " + System::DateTime::Now.ToString(), "Map Signer", MessageBoxButtons::OK, MessageBoxIcon::Information);
      }
     };
    }

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ and VB to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code



  • Sculli

    Ok thanks, I got that last error fixed but how come when I debug and run it, when I click the close button (which is button3 by the way) it closes form1 but I have it set up so that when I click button1 it should close form1 then not by clicking button3. Look at the code above, it says button1's click event not button3's should close form1 and open form2. I don't get that.

  • Luca Bolognese

    I'm doing it in Visual C++ 2005 Express Edition. What Version exactly are you doing it in

  • Deadman

    Try using...

    Application::Run(gcnew frmSigner());

    instead of...

    Application::Run(gcnew Form1());


  • Santosh

    Thanks it worked, but I got one last error:

    ------ Build started: Project: Map_Maker_Worker, Configuration: Debug Win32 ------

    Compiling...

    Map_Maker_Worker.cpp

    .\Map_Maker_Worker.cpp(16) : error C2061: syntax error : identifier 'Form1'

    Build log was saved at "file://c:\Documents and Settings\Aaron Chapman\My Documents\Visual Studio 2005\Projects\Map_Maker_Worker\Map_Maker_Worker\Debug\BuildLog.htm"

    Map_Maker_Worker - 1 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    and when I follow it, it takes me to the actual project code rather than the form1 code:

    // Map_Maker_Worker.cpp : main project file.

    #include "stdafx.h"

    #include "Form1.h"

    using namespace Map_Maker_Worker;

    [STAThreadAttribute]

    int main(array<System::String ^> ^args)

    {

    // Enabling Windows XP visual effects before any controls are created

    Application::EnableVisualStyles();

    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it

    Application::Run(gcnew Form1());

    return 0;

    }



  • jomo

     orokulus wrote:

      In the final version of Visual C++, Dispose methods don't appear in windows forms.

    Change the following code...

    private protected:
      virtual void Dispose(Boolean disposing) override
      {
       if(disposing)
       {
     if (components != nullptr)
     {
      delete components;
     }
       }
       __super::Dispose(disposing);
      }

    ... for this another one:

     protected:
      ~frmSigner()    
    // ~ symbol and the class name
      {
       if (components)
       {
        delete components;
       }
      }

    Actually, ~<class name> is the C++/CLI equivalent of C#'s Dispose(), not Dispose(bool).  Dispose(bool) is used to help implement the standard dispose pattern, but could be named anything.  The latest build of Instant C++ renames Dispose(bool) to DisposeObject(bool).

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ and VB to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code



  • Terry Adams

    This is from our Instant C++ (C# Edition) converter - let me know how it works for you:

    using namespace System;
    using namespace System::Drawing;
    using namespace System::Collections;
    using namespace System::ComponentModel;
    using namespace System::Windows::Forms;
    using namespace System::Data;

    namespace Map_Maker_Worker
    {
     /// <summary>
     /// Dialog for a useless application that runs a checksum on multiple maps.
     /// </summary>
     public ref class frmSigner : System::Windows::Forms::Form
     {
      private:
      System::Windows::Forms::Button ^btnSelectMaps;
      System::Windows::Forms::Button ^btnRemove;
      System::Windows::Forms::Button ^btnSign;
      System::Windows::Forms::ListBox ^lbx;
      System::Windows::Forms::OpenFileDialog ^ofd;
      System::Windows::Forms::Label ^lblAuthor;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      System::ComponentModel::Container ^components;

      public:
      frmSigner()
      {
       //
       // Required for Windows Form Designer support
       //
       InitializeComponent();
       //
       // TODO: Add any constructor code after InitializeComponent call
       //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      public protected:
      virtual void Dispose(Boolean disposing) override
      {
       if(disposing)
       {
     if (components != nullptr)
     {
      delete components;
     }
       }
       __super::Dispose(disposing);
      }

      #pragma region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private:
      void InitializeComponent()
      {
       System::Resources::ResourceManager ^resources = gcnew System::Resources::ResourceManager(frmSigner::typeid);
       this->btnSelectMaps = gcnew System::Windows::Forms::Button();
       this->btnRemove = gcnew System::Windows::Forms::Button();
       this->btnSign = gcnew System::Windows::Forms::Button();
       this->lbx = gcnew System::Windows::Forms::ListBox();
       this->ofd = gcnew System::Windows::Forms::OpenFileDialog();
       this->lblAuthor = gcnew System::Windows::Forms::Label();
       this->SuspendLayout();
       //
       // btnSelectMaps
       //
       this->btnSelectMaps->BackColor = System::Drawing::Color::Transparent;
       this->btnSelectMaps->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnSelectMaps->ForeColor = System::Drawing::Color::White;
       this->btnSelectMaps->Location = System::Drawing::Point(48, 62);
       this->btnSelectMaps->Name = "btnSelectMaps";
       this->btnSelectMaps->Size = System::Drawing::Size(96, 24);
       this->btnSelectMaps->TabIndex = 0;
       this->btnSelectMaps->Text = "Add Maps";
       this->btnSelectMaps->Click += gcnew System::EventHandler(this, &frmSigner::btnSelectMaps_Click);
       //
       // btnRemove
       //
       this->btnRemove->BackColor = System::Drawing::Color::Transparent;
       this->btnRemove->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnRemove->ForeColor = System::Drawing::Color::White;
       this->btnRemove->Location = System::Drawing::Point(48, 88);
       this->btnRemove->Name = "btnRemove";
       this->btnRemove->Size = System::Drawing::Size(96, 24);
       this->btnRemove->TabIndex = 1;
       this->btnRemove->Text = "Remove Maps";
       this->btnRemove->Click += gcnew System::EventHandler(this, &frmSigner::btnRemove_Click);
       //
       // btnSign
       //
       this->btnSign->BackColor = System::Drawing::Color::Transparent;
       this->btnSign->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
       this->btnSign->ForeColor = System::Drawing::Color::White;
       this->btnSign->Location = System::Drawing::Point(496, 88);
       this->btnSign->Name = "btnSign";
       this->btnSign->Size = System::Drawing::Size(96, 24);
       this->btnSign->TabIndex = 2;
       this->btnSign->Text = "Sign Maps";
       this->btnSign->Click += gcnew System::EventHandler(this, &frmSigner::btnSign_Click);
       //
       // lbx
       //
       this->lbx->BackColor = System::Drawing::Color::Black;
       this->lbx->BorderStyle = System::Windows::Forms::BorderStyle::None;
       this->lbx->ForeColor = System::Drawing::Color::White;
       this->lbx->HorizontalScrollbar = true;
       this->lbx->Location = System::Drawing::Point(152, 328);
       this->lbx->Name = "lbx";
       this->lbx->SelectionMode = System::Windows::Forms::SelectionMode::MultiExtended;
       this->lbx->Size = System::Drawing::Size(328, 117);
       this->lbx->TabIndex = 3;
       //
       // lblAuthor
       //
       this->lblAuthor->BackColor = System::Drawing::Color::Transparent;
       this->lblAuthor->ForeColor = System::Drawing::Color::PaleTurquoise;
       this->lblAuthor->Location = System::Drawing::Point(506, 426);
       this->lblAuthor->Name = "lblAuthor";
       this->lblAuthor->Size = System::Drawing::Size(88, 16);
       this->lblAuthor->TabIndex = 4;
       this->lblAuthor->Text = "The Swamp Fox";
       //
       // frmSigner
       //
       this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
       this->BackgroundImage = (safe_cast<System::Drawing::Image^>(resources->GetObject("$this.BackgroundImage")));
       this->ClientSize = System::Drawing::Size(632, 446);
       this->Controls->Add(this->lblAuthor);
       this->Controls->Add(this->lbx);
       this->Controls->Add(this->btnSign);
       this->Controls->Add(this->btnRemove);
       this->Controls->Add(this->btnSelectMaps);
       this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
       this->MaximizeBox = false;
       this->Name = "frmSigner";
       this->Text = "Plz Make My Maps Work!!1";
       this->ResumeLayout(false);

      }
      #pragma endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application::Run(gcnew frmSigner());
      }

      void btnSelectMaps_Click(Object ^sender, System::EventArgs ^e)
      {
       ofd->Title = "Select map(s).";
       ofd->Filter = "Halo 2 Map File (*.map)|*.map|All Files (*.*)|*.*";
       ofd->FileName = ".map";
       ofd->Multiselect = true;

       if(ofd->ShowDialog() == DialogResult::OK)
     lbx->Items->AddRange(ofd->FileNames);
      }

      void btnRemove_Click(Object ^sender, System::EventArgs ^e)
      {
       int nCount = lbx->Items->Count;
       for(int nIndex = nCount - 1; nIndex >= 0; nIndex--)
     if(lbx->SelectedIndices->Contains(nIndex))
      lbx->Items->RemoveAt(nIndex);
      }

      void btnSign_Click(Object ^sender, System::EventArgs ^e)
      {
       System::DateTime dtStart = System::DateTime::Now;
       for each(String ^sMap in lbx->Items)
       {
     System::IO::FileStream ^fs = gcnew System::IO::FileStream(sMap, System::IO::FileMode::Open, System::IO::FileAccess::ReadWrite, System::IO::FileShare::Read);
     if(fs->Length % 4 != 0)
     {
      MessageBox::Show("The map " + sMap + " is not even bounded to four...You really screwed something up, and it will not be signed.", "Map Signer", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
      continue;
     }
     int nChecksum = 0;
     System::IO::BinaryReader ^br = gcnew System::IO::BinaryReader(fs);
     br->BaseStream->Position = 0x800;
     int nEndOfFile = safe_cast<int>(fs->Length);
     for(int x = 0x800; x < nEndOfFile; x += 4)
      nChecksum ^= br->ReadInt32();
     fs->Position = 0x2d0;
     fs->Write(BitConverter::GetBytes(nChecksum), 0, 4);
     br->Close();
     fs->Close();
     fs = nullptr;
       }
       MessageBox::Show("Complete!\nStart Time: " + dtStart.ToString() + "\nFinish Time: " + System::DateTime::Now::ToString(), "Map Signer", MessageBoxButtons::OK, MessageBoxIcon::Information);
      }
     };
    }

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ and VB to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code



  • Grigory_

    I tried it again and I got these errors:

     

    ------ Build started: Project: Map_Maker_Worker, Configuration: Debug Win32 ------

    Compiling...

    Map_Maker_Worker.cpp

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(44) : error C2605: 'Dispose' : this method is reserved within a managed class

    did you intend to define a destructor

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(43) : warning C4490: 'override' : incorrect use of override specifier; 'Map_Maker_Worker::frmSigner::Dispose' does not match a base ref class method

    'new' or 'override' are only allowed when a matching base method from a ref class exists

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(52) : error C2794: 'Dispose' : is not a member of any direct or indirect base class of 'Map_Maker_Worker::frmSigner'

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(165) : error C2039: 'OK' : is not a member of 'System::Windows::Forms::Form::DialogResult'

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(14) : see declaration of 'System::Windows::Forms::Form::DialogResult'

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(165) : error C2065: 'OK' : undeclared identifier

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(200) : error C2039: 'ToString' : is not a member of 'System::DateTime::Now'

    c:\documents and settings\<removed>\my documents\visual studio 2005\projects\map_maker_worker\map_maker_worker\Form1.h(179) : see declaration of 'System::DateTime::Now'

    .\Map_Maker_Worker.cpp(16) : error C2061: syntax error : identifier 'Form1'

    Build log was saved at "file://c:\Documents and Settings\<removed>\My Documents\Visual Studio 2005\Projects\Map_Maker_Worker\Map_Maker_Worker\Debug\BuildLog.htm"

    Map_Maker_Worker - 6 error(s), 1 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



  • Yusuke

    I also thought that Microsoft would have one - they may have one available soon.  Beyond that reason, there are a couple of further reasons we probably won't consider it:

    1. I don't think Managed C++ has enough active developers to warrant it.

    2. To develop a converter from C++ to anything else (even another 'version' of C++) is notoriously difficult.  That's why you won't find any converter that converts C++ code to anything else.

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# converter
    Instant VB: C# to VB.NET converter
    Instant C++: C# to C++ converter and VB to C++ converter
    Instant J#: VB.NET to J# converter
    Clear VB: Cleans up VB.NET code



  • JMMJ

      In the final version of Visual C++, Dispose methods don't appear in windows forms.

    Change the following code...

    private protected:
      virtual void Dispose(Boolean disposing) override
      {
       if(disposing)
       {
     if (components != nullptr)
     {
      delete components;
     }
       }
       __super::Dispose(disposing);
      }

     

    ... for this another one:

     protected:
      ~frmSigner()    
    // ~ symbol and the class name
      {
       if (components)
       {
        delete components;
       }
      }


  • Qmar

    Very cool product - would you ever consider writing a Managed C++ to C++/CLI converter   I think Microsoft was supposed to release one but never did. 
  • Dark Helmet

    I just pasted the converted code into an existing C++/CLI project and it only required one adjustment regarding DialogResult::OK.

    Other than that one adjustment, the code compiled fine with Visual Studio 2005.

    I'm not sure what the problem is - you're compiling with 2005 - right

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ and VB to C++ Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code



  • spiritualfields

    I tried your code and it had a few errors, I tried to fix as many as I could, and this is what I got:

    ------ Build started: Project: (Removed), Configuration: Debug Win32 ------

    Compiling...

    (Removed).cpp

    .\(Removed).cpp(6) : error C2143: syntax error : missing ';' before 'using'

    c:\documents and settings\(Removed)\my documents\visual studio 2005\projects\(Removed)\(Removed)\Form1.h(26) : error C2059: syntax error : 'inline function header'

    c:\documents and settings\(Removed)\my documents\visual studio 2005\projects\(Removed)\(Removed)\Form1.h(26) : error C2143: syntax error : missing ';' before '{'

    c:\documents and settings\(Removed)\my documents\visual studio 2005\projects\(Removed)\(Removed)\Form1.h(26) : error C2447: '{' : missing function header (old-style formal list )

    c:\documents and settings\(Removed)\my documents\visual studio 2005\projects\(Removed)\(Removed)\Form1.h(94) : fatal error C1903: unable to recover from previous error(s); stopping compilation

    Build log was saved at "file://c:\Documents and Settings\(Removed)\My Documents\Visual Studio 2005\Projects\(Removed)\(Removed)\Debug\BuildLog.htm"

    (Removed) - 5 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

     

    Could you please Help Me



  • A D SRIKANTH

    Yes

  • C# to C++