drag and drop on exe's

Started by
4 comments, last by benryves 18 years, 8 months ago
hi first of all i'm using fstream and VS 6. i'm writing a program that takes a file(.html or .txt) and does some stuff with it(what exactly doesn't matter). problem is, if i want the program to process a different file i have to get into the code and change the line that specifies the file location and name. i want to be able to just drop the files on the exe, how can i do that?
Advertisement
When you drop a file on top of an EXE, it passes the filename of that file in as the command-line parameter to that EXE.
Your program probably has a main() function that looks something like:
int main(int argc, char* argv[]) {    // ... code ...    return 0;}

argc is the number of command line arguments passed to your program, and argv[] is an array of those command line arguments. In your example of just dropping a file onto an EXE, argc will be "2" and argv[1] will contain the filename of that file you just dropped on. (argv[0] contains the filename of the EXE file itself).

EDIT: Fixed. [embarrass]

[Edited by - benryves on August 10, 2005 4:39:43 AM]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

or if the application is already open you will need to implement drag and drop for that application's window to accept the dropping of files.

There are many articles on this - i would be glad to give you some pointers if you can tell me what architecture you are using (ie. Win32 or MFC).
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Why not just give both?
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
thanks guys, benryves already answered what i needed to know.
just to clear things up(because i got it wrong the firs time):
argv[0] is the path of the exe
argv[1] is the path of the file you dropped on the exe
Quote:Original post by back2newbelf
argv[0] is the path of the exe
argv[1] is the path of the file you dropped on the exe
When I got home last night I suddenly remembered that I'd made the cock-up... glad you worked it out, in that case [smile]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

This topic is closed to new replies.

Advertisement