Menu

system call for c++

2002-11-07
2012-09-26
  • Nobody/Anonymous

    I wish to communicate with MS applications and/or system calls.  For instance, I have want my c++ program to execute Word for a user selected document and execute a macro.  How can I issue a DOS command (i.e. winword.exe <document> /m<macro>)?  Any ideas?  Any place I can find examples?

    Wayne

     
    • Nhan Le

      Nhan Le - 2002-11-14

      I thought you could use <stdlib.h> and use the "system()" function to solve your problem.

      'system("dir")' would display contents of you current working directory.

      Can "winword.exe" accept  arguments and switches from command line?

      :-\ Nhan

       
    • Nhan Le

      Nhan Le - 2002-11-14

      how do you extract enviroment varibles like "HOMEDRIVE", "windir", "SystemRoot" inside a program?

      I just thought up of a way of doing this, but i'm sure there is a better way of doing it.

      -make a "system()" call to call a batch file to echo the values
      -redirect the output to a file
      -read the file to obtain the enviroment varibles

      Someone show me a better way of doing this.

      :-)
      Nhan

       
    • Nobody/Anonymous

      Hmmm, I guess I am going to have to start signing my posts differently.

      Wayne

      oops, I'll go to one of my first screen names

      dockeen

       
    • Anonymous

      Anonymous - 2002-11-14

      Hi Wayne,
      I've included a section of code from one of my programs. This is from a Windows app
      where the user selects a pdf file from a listbox. Once the pdf file is selected the program
      then sends it to the ShellExecute function which passes the pdf to Adobe. Something
      similar should work with a doc file in winword.

                case ID_LISTBOX2:
                     if (CodeNotify == LBN_SELCHANGE)
                     {
                      HINSTANCE ShellInst;
                      int ShellRetInfo;
                      char PathBuf[100];
                      char CurDir[100];
                      GetCurrentDirectory(100,CurDir);
                      DlgDirSelectEx(hwnd,PathBuf,100,ID_LISTBOX2);
                      ShellInst = ShellExecute(hwnd,"open",PathBuf,NULL,CurDir,SW_MAXIMIZE);
                      if (!ShellInst)
                      MessageBox (NULL,"You must have Adobe Reader installed to view PDF files!","ERROR!!!", 0);
                     }
                     break;

      hope this helps,

      Dale

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.