Solved

Destroying an automation enabled class from within

Posted on 1998-08-07
5
193 Views
Last Modified: 2013-11-20
I have a CMdTarget derived automation enabled class (call it DocClass).

I want to provide a method (say "Close")to this automation class which
destroys itself.

How to do it?

"delete this" leads to assertion failure.

-----------
PS : My VB controller code reads like this:

sub Test()
Dim docs As DocCollection
Dim doc As DocClass
set DocCollection = Application.DocCollection
set doc = DocCollection.Item(1)

doc.Close   '' I want this line to destroy "doc" object and
            '' make it invalid object reference
            '' HOW TO IMPLEMENT THIS???

End sub
0
Comment
Question by:dvenkat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1320416
Should you not just release its refercence by doing a set Doc = nothing??
0
 
LVL 3

Accepted Solution

by:
Norbert earned 50 total points
ID: 1320417
This is not a MFC Problem Set Doc = nothing from VB does the work.
If the CMdTarget derived class has to do something special if the last reference to the class is released implement this  handling in the OnFinalRelease Function of your class.

I won't steal any points so if Set Doc=nothing is enough for you
please reject my answer an ask Andy Keys for answering the question
0
 

Author Comment

by:dvenkat
ID: 1320418
Norbert,

Thanks for your answer.

My problem is more fundamental and is related to MFC code (not VB controller code). Actually I am integrating VB scripting engine to my application ('s object hierarchy).

This means, at run time when I create my scripting dialog, I instantiate VB scripting engine, create a COM object, and attach it to the VB scripting engine's name space (say with the name "Application", so that I can make reference to this object in my VB script and go from there.

However when I want to exit the scripting engine, scripting engine is NOT decrementing the reference count of this object (added to its name space). I do not know why (as such there is no need for you to explicitely delete automation objects (ActiveX engine does it for when the reference count =0).

Since the reference count is not getting decremented, even after my application exits, I have a ghost lingering! (You have to go to "running processess view" to kill it). By now you would have figured out my real problem: since the reference count is != 0, when I "close" the application, the ActiveX engine is really NOT closing the project! It just goes invisible.

I thought, doing "delete this" at destructor may help. But it is not helping. Perhaps I have design problem.

Anyway thanks for your effort and answer.
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1320419
Because the destuctor is not called when the Object is not released delete this can not help.
You Asked in your question for
doc.Close   
did you try doc.Release() ?
0
 

Author Comment

by:dvenkat
ID: 1320420
In the MFC code, calling explicitely "OnFinalRelaease" before calling "delete" of this object created with "new" solves the problem.

Thanks

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 55
windows 10 how make picture as desktop background 2 73
ffmpeg - "rtsp://...... Operation not permitted" 4 92
MaxSpan challenge 9 140
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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