Solved

OLE Control

Posted on 1998-05-17
3
236 Views
Last Modified: 2013-11-25
Hello,
I am tryng to control a Word 8.0 session throughout a C++ program
via OLE mechanism.
I want my C program, after the activation of Word, be waiting for the
closure of Word session, and then take again control.
Now my program doesn't work this way because, after the OLE activation
I have no more information about the process,(I look for something like WaiforSingleProcess ...)
It seems to me that no parameters in the ole call is good for my goal.
Neverless ... this sound to me a usual problem in Ole Automation ...
 
The hearth of my code is:

    // Create an instance of the automation object and ask for the IDispatch interface
    hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER,
                          IID_IUnknown, (void FAR* FAR*)&punk);
    if (FAILED(hr))
        goto error;
                   
    hr = punk->QueryInterface(IID_IDispatch, (void FAR* FAR*)&pdisp);
    if (FAILED(hr))
        goto error;

    *ppdisp = pdisp;
    punk->Release();

I do obtain pointer to the memory exchange area,
but can't have information about the process underlying (the Word process).
So, ... after this call, my process goes on, and I haven't information
about the closure of the process...

I look forward for an answer from an experienced C programmer.

                        Thank you
                       Santo

0
Comment
Question by:camporelle
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 150 total points
ID: 1162688
OLE automation is supposed to be used when the server is doing something useful for you. If the server has a UI and is started as a server, the UI interaction cannot cause the program to really exit. The UI interaction will only cause the UI to go away. The server is still running, although there is no UI. The controller has full control over when the server can run and not run. No UI interaction can break that contract between the controller and server.

If you want to know when the user wants to quit, then I would suggest subclassing the main window of Word and catch the WM_DESTROY message.

Another idea is to not use automation, but use CreateProcess() and use WaitForSingleObject() to know when the process has terminated.
0
 

Expert Comment

by:footloose
ID: 1162689
You might want consider writing a WordBasic macro to notify your application (like posting a message or writing a semaphore file) when it exits.
0
 

Author Comment

by:camporelle
ID: 1162690
I can't use CreateProcess because I have no more a OLE connection.
More interesting the subClassing.
How can I do it ?
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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.
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.

762 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

22 Experts available now in Live!

Get 1:1 Help Now