drag and drop on exe's
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?
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:
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]
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]
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).
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).
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
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 back2newbelfWhen I got home last night I suddenly remembered that I'd made the cock-up... glad you worked it out, in that case [smile]
argv[0] is the path of the exe
argv[1] is the path of the file you dropped on the exe
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement