15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


How to implement doc.Close

David Shillito -- David_Shillito@msn.com
Monday, January 20, 1997

Environment: NT 4.0, MSVC 4.1

I am having difficulty trying to implement the automation method Close() on my 
document object which is derived from COleServerDocument .

I found the sample XRTFRAME on the MSDN CD and used a lot of the code from it 
but the Close method (in DOC.CPP) doesnt seem to actually delete the document. 
It sets m_bAutoDelete to FALSE and then calls OnCloseDocument. The document 
object itself is only deleted in OnFinalRelease. This implies that the 
document still exists after Close and it will only be released when the client 
(VB for example) does a Set theDoc = Nothing or lets the object variable go 
out of scope. That allows the possibility that the client could actually try 
to call further methods of the document after calling Close - whjich would 
lead to some interesting behavior on this 99% closed document object!

Substituting Excel for my automation server I have been able to demonstrate 
the Excel DOES release the object during the Close method (on a WorkBook, i.e. 
a document).

If I modify my server to delete the document as part of the Close method then 
I get an Application Error on the OLE automation libraries. I dont think it is 
permissible to delete this in an automation method since, for example, the 
code for COleDispatchImpl::Invoke in OLEDISP1 does

	// restore original m_bResultExpected flag
	pThis->m_bResultExpected = bResultExpected;

after my method code returns, and pThis at this time will have been released.

Does anyone else have any experience of implementing similar server behavior, 
i.e.

Set w = myApp.WorkBooks.Add
w.SomeManipulation
w.Close ' <<<<<< this method

and could you explain what is going on and how to code around this in MFC?

David Shillito



Scott Daniels -- scottdfl@sprynet.com
Wednesday, January 22, 1997

[Mini-digest: 2 responses]

 Environment: Win95, MSVC 4.1

I would like to use a list control just like that used in Internet Mail for
multi-column data. I don't care for the CListCtrl because the selection and
mouse-down to select only applies to the first column. In other words, you
must click on the first column in order to select a line. I know I can
implement what I want using the CHeaderCtrl with a CListBox, but it is not
as automatic as the CListCtrl. Are there any such controls or classes
available?

Thanks very much,
Scott Daniels             scottdfl@sprynet.com
"Life appears the way you choose to see it."
-----From: mfc-l@netcom.com

>From mfc-l Mon Jan 20 10:31:33 UT 1997 remote from netcom.com
Received: from netcom.com by tc4d1.cmc.stph.net; Wed, 22 Jan 1997 20:24 EST
Received: by majordomo.netcom.com (8.7.5/8.7.3/(NETCOM MLS v1.01)) id IAA07296; Tue, 21 Jan 1997 08:42:48 -0800 (PST)
Date: Mon, 20 Jan 97 10:31:33 UT
From: "David Shillito" 
Message-Id: 
To: "MFC-L mailing list" 
Subject: How to implement doc.Close
Sender: owner-mfc-l@majordomo.netcom.com
Errors-To: owner-mfc-l@majordomo.netcom.com
Precedence: bulk
Reply-To: mfc-l@netcom.com
Content-Type: text
Content-Length: 1741

Environment: NT 4.0, MSVC 4.1

I am having difficulty trying to implement the automation method Close() on my 
document object which is derived from COleServerDocument .

I found the sample XRTFRAME on the MSDN CD and used a lot of the code from it 
but the Close method (in DOC.CPP) doesnt seem to actually delete the document. 
It sets m_bAutoDelete to FALSE and then calls OnCloseDocument. The document 
object itself is only deleted in OnFinalRelease. This implies that the 
document still exists after Close and it will only be released when the client 
(VB for example) does a Set theDoc = Nothing or lets the object variable go 
out of scope. That allows the possibility that the client could actually try 
to call further methods of the document after calling Close - whjich would 
lead to some interesting behavior on this 99% closed document object!

Substituting Excel for my automation server I have been able to demonstrate 
the Excel DOES release the object during the Close method (on a WorkBook, i.e. 
a document).

If I modify my server to delete the document as part of the Close method then 
I get an Application Error on the OLE automation libraries. I dont think it is 
permissible to delete this in an automation method since, for example, the 
code for COleDispatchImpl::Invoke in OLEDISP1 does

	// restore original m_bResultExpected flag
	pThis->m_bResultExpected = bResultExpected;

after my method code returns, and pThis at this time will have been released.

Does anyone else have any experience of implementing similar server behavior, 
i.e.

Set w = myApp.WorkBooks.Add
w.SomeManipulation
w.Close ' <<<<<< this method

and could you explain what is going on and how to code around this in MFC?

David Shillito




| Вернуться в корень Архива |