Invoking MSWord

This is a discussion on Invoking MSWord within the C Programming forums, part of the General Programming Boards category; I've used the following code to invoke MSWord from a DOS based C compiler unsuccessfully....Where am I going wrong? #include ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    19

    Unhappy Invoking MSWord

    I've used the following code to invoke MSWord from a DOS based C compiler unsuccessfully....Where am I going wrong?

    #include <stdio.h>
    #include <stdlib.h>

    main()
    {
    system("C:\helpme!.doc");
    }

    Thanks in advance.

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    It should be
    Code:
    system("C:\\myme!.doc");

  3. #3
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    first main() should return a value.
    second you'll need an extra slash for the file name.

    Code:
    #include <stdlib.h> 
    
    int main()
    {
    	system("C:\\helpme!.doc"); 
    
    	return 0;
    }

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    19

    Still trying to invoke separate application

    I revised the program (i.e. put the extra slash in and put in int main() and return 0) and I still get a "Bad command or file name" when I try to execute the program. Any other suggestions? Appreciate the help.

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Not to sound condescending: Are you sure the file's there?

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    Yep, the files there. I thought of that...I tried on various files to try to get this working. I also tried different things on the system function such as a "copy" and "dir" and those things work correctly as far as I saw.

  7. #7
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    OK - try smth like this:

    system("c:\\winword mydoc.doc");

    I don't know if Word will take parameters like that, but it works with notepad...

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    I tried:

    system("c:\\winword mydoc.doc");

    and

    just for laffs,

    system("c:\\winword.exe mydoc.doc");

    But, unfortunately, it's a no go on both lines....

  9. #9
    Barjor
    Guest
    If you go to your command prompt and type >>C:\helpme!.doc<<
    does that open the document?

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Include windows.h and use one of the ShellExecute family of functions. There is info on this at msdn.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    That's just it. When I go to the command prompt and type in my document name (i.e. >>c:\mydoc.doc<<) , MSWord does start up. But I can't get it to start up within my program. That's why I figured that I may have been missing something (possibly in my use of the system function).

  12. #12
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    I'm shootin' in the dark, but try one of the spawn functions (they work better, anyways)

  13. #13
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    what is the name of the file you are trying to open?

  14. #14
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Well you could use the full path to microsoft word.

  15. #15
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    A document file is not the same as an executable file. Govtcheez had the right idea, but try this instead:
    Code:
    #include "stdafx.h"
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    	system("c:\\helpme!.doc >> C:\\WINWORD");
    	return 0;
    }
    Last edited by Witch_King; 09-07-2001 at 04:46 PM.
    I compile code with:
    Visual Studio.NET beta2

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Invoking constructor from another constructor
    By @nthony in forum C++ Programming
    Replies: 1
    Last Post: 11-12-2008, 12:12 AM
  2. invoking Base::virtualMethod() instead of Derived
    By noobcpp in forum C++ Programming
    Replies: 11
    Last Post: 11-08-2008, 01:16 PM
  3. invoking C# function from C++
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2007, 09:09 AM
  4. segmentation fault when invoking new
    By George2 in forum C++ Programming
    Replies: 13
    Last Post: 05-15-2006, 06:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21