9 Replies - 7602 Views - Last Post: 05 March 2010 - 02:17 PM Rate Topic: -----

#1 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Drag and drop onto exe

Posted 04 March 2010 - 05:34 AM

I have written a c++ application that will process a file at a hardcoded location and output a text file.

How can I make my application so that a file is dropped onto the exe and the filename/location is passed to my functions?

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Drag and drop onto exe

#2 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Drag and drop onto exe

Posted 04 March 2010 - 06:11 AM

int main(int argc, char *argv[])
{
   //argv[0] is your exe file name with its path.
   //Your filenames start from argv[1]
   if(argc<2)
   {
      cout<<"Drag and drop files to the exe"<<endl;
      cin.get()
      return 0;
   }
   else
   {
     //do something
   }
   return 0;
}


Was This Post Helpful? 1
  • +
  • -

#3 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Drag and drop onto exe

Posted 04 March 2010 - 06:42 AM

Works perfectly, thanks very much
Was This Post Helpful? 0
  • +
  • -

#4 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Drag and drop onto exe

Posted 04 March 2010 - 07:13 AM

Actually, I'm having a problem now with text files not being output if a file has been dragged onto the exe. How can I solve this?
Was This Post Helpful? 0
  • +
  • -

#5 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Drag and drop onto exe

Posted 04 March 2010 - 08:35 AM

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
   if(argc<2)
      cout<<"Drag and drop files to the exe"<<endl;
   else
   {
      string line;
      for(int i=1;i<argc;i++)
      {
         cout<<"File name is : "<<argv[i]<<endl;
         ifstream fi(argv[i]); //assuming it as a text file, open file for reading
         while(getline(fi,line))  //read line till end of file
            cout<<line<<endl;

         cout<<endl;
      }
   }
   cin.get();
   return 0;
}


Was This Post Helpful? 0
  • +
  • -

#6 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Drag and drop onto exe

Posted 04 March 2010 - 11:19 AM

Ah, sorry, you misunderstand. I'm trying to save information to a text file based on the input file.

Is there any reason why
int imagetotext(){

	ofstream outfile;
	outfile.open ("output.txt");

	for (int curY = 0; curY <18; curY++){
		for (int curX = 0; curX < 38; curX++){

			int r = getr(getpixel(newframe, curX, curY));
			int g = getg(getpixel(newframe, curX, curY));
			int b = getb(getpixel(newframe, curX, curY));
			int colour = getcolour(r,g,B)/>;
			
			outfile << colour << " ";

		}

		outfile << "\n";
	}

	outfile.close();

	return 0;
}


would suddenly stop working?
Was This Post Helpful? 0
  • +
  • -

#7 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Drag and drop onto exe

Posted 05 March 2010 - 01:13 PM

In the above code,your file handling looks fine.
We may need more information about your program to help you in this.
What is the error do you get? Does your program terminate unexpectedly? Please post the output file.
It may be that your functions (getr,getpixel etc) are acting weird. Please post the code.
Was This Post Helpful? 0
  • +
  • -

#8 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Drag and drop onto exe

Posted 05 March 2010 - 01:20 PM

I'm actually talking a little about it here as well: http://www.dreaminco...topic160022.htm

The program doesn't end. A file was output perfectly before adding the argc argv stuff. At the moment no text file is created, this is the only problem with my program.

I THINK it may have something to do with streams, but I don't know anything about them.
Was This Post Helpful? 0
  • +
  • -

#9 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Drag and drop onto exe

Posted 05 March 2010 - 01:37 PM

I am not sure of what's going on.
You may want to test the file creation with a sample code.
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
   if(argc<2)
      cout<<"Drag and drop the file(s) to the exe"<<endl;
   else
   {
      ofstream fo("output.txt");
      if(!fo)
      {
         cout<<"File could not be created"<<endl;
         return 1;
      }
      for(int i=1;i<argc;i++)
         fo<<argv[i]<<endl;
      fo.close();
      cout<<"Finished"<<endl;
   }
   cin.get();
   return 0;
}


This code works perfectly for me.
Was This Post Helpful? 0
  • +
  • -

#10 theholygod  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 342
  • Joined: 05-February 06

Re: Drag and drop onto exe

Posted 05 March 2010 - 02:17 PM

Ugh, sorry for the hassle, the txt file is going to "my documents" for some reason.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1