Solved

Launching Winword from C++

Posted on 1998-12-30
6
367 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

18 Experts available now in Live!

Get 1:1 Help Now