Q. About OLE Automation & OLE compound document support
Edelmiro Fuentes -- Edelmiro.Fuentes@cui.unige.ch
Friday, June 14, 1996
Hello,
Environment: Window NT 4.0 (build 1234)
Visual C++ 4.0
I created an MDI automation server application. I used all the defaults
suggested by the AppWizard (except, of course, the OLE automation support
which I selected). This server exposes two methods:
void ShowWindow() (taken from the AUTOCLICK example)
=>displays the window when an automation controller connects
and
BSTR SendGreetings()
=>sends a dummy message to the client.
For the automation client, I made in the same way. I used all the defaults
from AppWizard and I selected the OLE automation support.
I added a class from the OLE Type Lib created by the Server.
For the connection, I create the dispatch in the OnNewDocument function and
invoke ShowWindow:
//------------------------------------------------------------
COleException exc;
if (!m_ctxolesrv.CreateDispatch(_T("Srv2Test.Document"), &exc))
{
AfxMessageBox("Cannot Create Server");
return FALSE; // fail
}
m_ctxolesrv.ShowWindow();
//---------------------------------------------------------------
It works OK. When the automation client starts, the server starts
automatically and displays the "document" window opened by the client.
When the client exits, the window displayed in the server is closed.
If there are no more open documents, the server exits itself.
The problem starts when I modified the server in order to have the OLE
compound document support (as a full-server).
I create a new automation server application exactly in the same way as
before. The only difference is that I also select OLE compound document
support as a full-server.Everything seems to work in the same way but when
the client exits,
the window opened in the server by this client remains open. And when
I try to close manually this window in the server, a dialog window
appears asking me if I want to save changes to a document that I never modified.
- Is this behaviour normal?
- How can I make the server to close the document? (I've already tried
the ReleaseDispatch() but it did not work) .
- Why and when is the modified flag set to true?
Thanks in advance for your help
Edelmiro
--------------------------------------------------------------------
Edelmiro Fuentes Edelmiro.Fuentes@cui.unige.ch
Centre Universitaire d'Informatique
24, Rue General-Dufour Tel. +41 (22) 705 76 71
CH-1211 GENEVE 4 SWITZERLAND Fax. +41 (22) 705 77 80
--------------------------------------------------------------------
Edelmiro Fuentes -- Edelmiro.Fuentes@cui.unige.ch
Tuesday, June 25, 1996
Hello,
Environment: Window NT 4.0 (build 1234)
Visual C++ 4.0
I created an MDI automation server application. I used all the defaults
suggested by the AppWizard (except, of course, the OLE automation support
which I selected). This server exposes one method:
//-------------------------------------------------------------
// displays the window when an automation controller connects
// taken from the AUTOCLICK example
void CSrv2TestDoc::ShowWindow()
{
// TODO: Add your dispatch handler code here
POSITION pos = GetFirstViewPosition();
CView* pView = GetNextView(pos);
if (pView != NULL)
{
CFrameWnd* pFrameWnd = pView->GetParentFrame();
pFrameWnd->ActivateFrame(SW_SHOW);
pFrameWnd = pFrameWnd->GetParentFrame();
if (pFrameWnd != NULL)
pFrameWnd->ActivateFrame(SW_SHOW);
}
}
//----------------------------------------------------------------
For the automation client, I also used all the defaults from AppWizard and I
selected the OLE automation support.
With the ClassWizard, I added a class from the OLE Type Lib created by the
Server.
For the connection, I create the dispatch in the OnNewDocument function and
invoke ShowWindow:
//------------------------------------------------------------
COleException exc;
if (!m_ctxolesrv.CreateDispatch(_T("Srv2Test.Document"), &exc))
{
AfxMessageBox("Cannot Create Server");
return FALSE; // fail
}
m_ctxolesrv.ShowWindow();
//---------------------------------------------------------------
It works OK. When the automation client starts, the server starts
automatically and displays the "document" window opened by the client.
When the client exits, the window displayed in the server is closed.
If there are no more open documents, the server exits itself.
The problem starts when I modified the server in order to have the OLE
compound document support (as a full-server).
I create a new automation server application exactly in the same way as
before. The only difference is that I also select OLE compound document
support as a full-server. Everything seems to work in the same way but when
the client exits, the window opened in the server by this client remains
open. And when I try to close manually this window in the server, a dialog
window appears asking me if I want to save changes to a document that I
never modified.
- Is this behaviour normal?
- How can I make the server to close the document? (I've already tried invoking
the ReleaseDispatch() in the client but it did not work) .
- Why and when is the modified flag set to true?
Thanks in advance for your help
Edelmiro
--------------------------------------------------------------------
Edelmiro Fuentes Edelmiro.Fuentes@cui.unige.ch
Centre Universitaire d'Informatique
24, Rue General-Dufour Tel. +41 (22) 705 76 71
CH-1211 GENEVE 4 SWITZERLAND Fax. +41 (22) 705 77 80
--------------------------------------------------------------------
Alberto Massari -- alby@belva.laboratorium.dist.unige.it
Friday, June 28, 1996
At 08:37 AM 6/25/96 +0000, you wrote:
>
>- Is this behaviour normal?
>
>- How can I make the server to close the document? (I've already tried invoking
> the ReleaseDispatch() in the client but it did not work) .
>
>- Why and when is the modified flag set to true?
At this time, I have an answer only for the last question: by default, every
document created via OLE starts "dirty", that is, the MFC code explicitly
calls SetModifiedFlag().
Alberto Massari
-----------------------------------------------------------------------
Alby@MusArt.dist.unige.it is: Alberto Massari
Computer Music Lab
Universy of Genoa -ITALY- http://MusArt.dist.unige.it/~alby/
-----------------------------------------------------------------------
| Вернуться в корень Архива
|