Windows Explorer Drag and Drop for CLI Arugments

Discussion in 'C++' started by Patrick Kramer, Nov 8, 2005.

  1. I'm building a file format converter for someone who at best takes more
    than his fair share of IT helpdesk hours :D

    So I want to make it as simple as possible. What I want it to do is,
    run:

    program.exe file.txt

    When I drop file.txt onto the executable file. In other words, take
    whatever file dropped onto the executable as the second CLI arugment.

    I don't know how this works, but I have seen it before with the OggDrop
    Encoder, where you drop your audio file onto the executable and it
    outputs an .ogg encoded file. I've also seen it in pure CLI
    executables.. But from working with the OggDrop Source I dont see
    anything that would allow me to do what they are doing. And the other
    utilities are closed source, so no luck there.

    Any Insights, Help or Misc. Commentary would be greatly appreciated.
     
    Patrick Kramer, Nov 8, 2005
    #1
    1. Advertising

  2. Patrick Kramer

    mlimber Guest

    Patrick Kramer wrote:
    > I'm building a file format converter for someone who at best takes more
    > than his fair share of IT helpdesk hours :D
    >
    > So I want to make it as simple as possible. What I want it to do is,
    > run:
    >
    > program.exe file.txt
    >
    > When I drop file.txt onto the executable file. In other words, take
    > whatever file dropped onto the executable as the second CLI arugment.
    >
    > I don't know how this works, but I have seen it before with the OggDrop
    > Encoder, where you drop your audio file onto the executable and it
    > outputs an .ogg encoded file. I've also seen it in pure CLI
    > executables.. But from working with the OggDrop Source I dont see
    > anything that would allow me to do what they are doing. And the other
    > utilities are closed source, so no luck there.
    >
    > Any Insights, Help or Misc. Commentary would be greatly appreciated.


    That's an OS issue, not so much a programming issue, and so it's
    off-topic here. The C++ question would be related to argc and argv, and
    if you need help with that, just ask.

    Cheers! --M
     
    mlimber, Nov 8, 2005
    #2
    1. Advertising

  3. Patrick Kramer

    Marcus Kwok Guest

    Patrick Kramer <> wrote:
    > I'm building a file format converter for someone who at best takes more
    > than his fair share of IT helpdesk hours :D
    >
    > So I want to make it as simple as possible. What I want it to do is,
    > run:
    >
    > program.exe file.txt
    >
    > When I drop file.txt onto the executable file. In other words, take
    > whatever file dropped onto the executable as the second CLI arugment.
    >
    > I don't know how this works, but I have seen it before with the OggDrop
    > Encoder, where you drop your audio file onto the executable and it
    > outputs an .ogg encoded file. I've also seen it in pure CLI
    > executables.. But from working with the OggDrop Source I dont see
    > anything that would allow me to do what they are doing. And the other
    > utilities are closed source, so no luck there.
    >
    > Any Insights, Help or Misc. Commentary would be greatly appreciated.


    <off-topic>
    There is no special facility needed, as long as your program handles
    argc/argv properly. If you drag and drop files onto the program, it
    will pass each file as a command line parameter. Try dragging files
    onto this program:



    #include <iostream>
    #include <string>

    int main(int argc, char* argv[])
    {
    if (argc < 2) {
    std::cout << "no files!\n";
    }
    else {
    // argv[0] is probably program name, so skip it
    for (int i = 1; i < argc; ++i) {
    std::cout << argv << '\n';
    }
    }

    // to pause the screen
    std::cout << "\n\nPress <Enter> to quit.\n";
    std::string trash;
    std::getline(std::cin, trash);

    return 0;
    }


    </off-topic>

    --
    Marcus Kwok
     
    Marcus Kwok, Nov 8, 2005
    #3
  4. That's what I needed..

    I wrote an exploratory program that excepted CLI arguments in command
    prompt and then ouputed the file as output.txt. It worked within the
    command prompt, but didn't do anything when I dragged and dropped to
    the executable in windows.

    I figured I was doing something wrong (apparently :D).. But I'll just
    work off the code you submitted, as It does exactly what I want.

    Thanks.
     
    Patrick Kramer, Nov 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver Klein
    Replies:
    0
    Views:
    691
    Oliver Klein
    Aug 24, 2003
  2. Matthew Zimmer

    Drag and Drop in Windows error

    Matthew Zimmer, Nov 4, 2003, in forum: Java
    Replies:
    2
    Views:
    618
    Matthew Zimmer
    Nov 5, 2003
  3. twoeyedhuman1111
    Replies:
    4
    Views:
    441
    Ioannis Vranos
    May 1, 2005
  4. Mark
    Replies:
    1
    Views:
    803
    Alexey Smirnov
    Nov 17, 2009
  5. Tom Felker
    Replies:
    2
    Views:
    120
    Tom Felker
    Jul 1, 2003
Loading...

Share This Page