Hi Everyone, Im using visual studio 2010 windows form application.
I created a windows form application to add and remove files to a directory on the click of the button1.
The problem is that when I put it on a different computer, it can never find those files.. Its supposed to be a distributable program.. So it should always find the files and remove it. The file it is supposed to find and remove is a .dll file and then it replaces it with a new .dll file.
I read up on resource files as I saw somewhere that this is the only way to do it without making an installer.
Thing is Im not sure how to go about adding my .dll file to the program and then making the program copy the .dll file to the new directory.
This is what I have so far:
#pragma once
namespace ProgWithGUI {
using namespace System;
using namespace System::IO;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#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>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->ForeColor = System::Drawing::Color::Blue;
this->label1->Location = System::Drawing::Point(37, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(214, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Welcome to My Program";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// button1
//
this->button1->Location = System::Drawing::Point(95, 44);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(85, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"Install Crack";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(282, 88);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->MaximizeBox = false;
this->Name = L"Form1";
this->Text = L"My Crack";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
void ReplaceFile(String^ fileToMoveAndDelete,
String^ fileToReplace, String^ backupOfFileToReplace)
{
File::Replace(fileToMoveAndDelete, fileToReplace,
backupOfFileToReplace, false);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
String^ originalFile = "C:\\Program Files\\Software\\My.dll";
String^ fileToReplace = "C:\\Program Files\\Software\\My2.dll";
String^ backUpOfFileToReplace = "C:\\Program Files\\Software\\My.dll.bac";
Console::WriteLine("Move the contents of " + originalFile + " into "
+ fileToReplace + ", delete " + originalFile
+ ", and create a backup of " + fileToReplace + ".");
// Replace the file.
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace);
MessageBox::Show("Done");
}
catch (IOException^ ex)
{
MessageBox::Show(ex->Message);
}
}
};
}
What it does is delete My.dll and replace it with My2.dll... But it can never find My2.dll unless a path is given.. I dont want to give a path I want the My2.dll to be included in my Prog and used to replace My.dll. (resource???) Anyone have any tutorials or examples or sample code on how I would go about doing that?