Solved

Launching Winword from C++

Posted on 1998-12-30
6
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 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