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?

Recommended Answers

All 3 Replies

You wouldn't be making a crack right? Because that would be against the rules...

Definitely looks like a crack to me..

wwwwwwo.. U have a long name but do not assume..

It is not a crack actually.. it is just an example of what I would like to do.. It can easily be an exe or binary file rather than a dll file
Its for a program called blackra1n for the iphone.. I noticed that the developers were missing a dll file.. and every single time I have to download the dll file, place it in the same folder and then run the program for my iphone.
I was just curious as to how they got the program to include such a file or any files in it without making an installer.. If you see my previous posts you will see that I've made installers for my programs rather than doing it this way.. But I dont want to make an installer because if a user deletes the file then my program will not be able to work.. correct??

I was following this tutorial: http://syedgakbar.wordpress.com/2007/11/07/embedding-dll-and-binary-files-in-the-executable-applications/

Im not sure if I was allowed to link that above.. but I've been following it and everytime I try to get the file to extract from my .exe and be used by the lines:

String^ originalFile = "My.dll";
String^ fileToReplace = "C:\\Program Files\\Software\\My2.dll";
String^ backUpOfFileToReplace = "C:\\Program Files\\Software\\My.dll.bac";

It fails to find the file and it even fails to extract the file like the link says..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.