[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Launching Winword from C++

Posted on 1998-12-30
6
Medium Priority
?
376 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

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

Accepted Solution

by:
geithman earned 40 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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…
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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…
Suggested Courses

873 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