Solved

Launching Winword from C++

Posted on 1998-12-30
6
373 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

707 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