Solved

Launching Winword from C++

Posted on 1998-12-30
6
368 Views
Last Modified: 2011-09-20
Hi,

I made a DLL supposed to launch a Word session based on a particular document.
Equivalent to: Start/Run/winword.exe F:\WPSS_Start.doc

I'm using the function _spawnlp as follow:
lReturnCode = _spawnlp( _P_WAIT, "winword.exe", "F:\WPSS_Start.doc" , NULL );

The result is: Word is effectively launched, but with a default docuemnt (document1.doc) instead of my personal document.

Any idea what I have done wrong?
Thanx
Serge
0
Comment
Question by:SergeD
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1181305
There's nothing wrong, except that you have to use a _double_ backslash:
lReturnCode = _spawnlp( _P_WAIT, "winword.exe", "F:\\WPSS_Start.doc" , NULL );
 Anyway, it's always better to sue 'ShellExecute()', as it'll launch Word in the appropriate way:

ShellExecute ( NULL, "open", "f:\\WPSS_Start.doc", NULL, NULL, SW_SHOWNORMAL);
0
 

Author Comment

by:SergeD
ID: 1181306
Hi,

I tried the double-backslash, and it still doesn't work (even if this filename works with the ShellExecute)

thanx for the suggestion for ShellExecute but it is not exactly what I'm looking for. If I open a doc file with ShellExecute, the default Word session is used. I would like to open a new Word session, to get the handle, and to close it later on with no changes on the user's session.

Any idea?

0
 
LVL 11

Expert Comment

by:alexo
ID: 1181307
Try using the short filename of the file.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:alexo
ID: 1181308
Another option: use CreateProcess() WinExec()
0
 

Accepted Solution

by:
geithman earned 20 total points
ID: 1181309
Try

lReturnCode = _spawnlp( _P_WAIT, "winword.exe", "c:\\office\\winword.exe F:\\WPSS_Start.doc" , NULL );

because the paramter-string (if any) has to begin with the path to the calles programm; this means, winword will open the second paramter in your parameter-list; some programms will not start, if the first parameter doesn't point to the executable...

0
 

Author Comment

by:SergeD
ID: 1181310
It works but now I need to know how to get the path of the installed word.

Thanx anyway.

Serge
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now