Solved

ActiveX reference count

Posted on 1998-01-21
4
256 Views
Last Modified: 2013-12-03
Hello, I checked the following structure:
console application(process 1) call ActiveX exe(process 2), I'll call it exe1.
the ActiveX exe call ActiveX dll, I'll call it dll1, the dll call a nother ActiveX exe, called exe2.

reference count is r.c.

1. r.c in console for exe1 is 1 and in exe1 it is 4, why ?
2. passing this from exe1 to dll to exe2 and assigning a smart pointer to it increase r.c to exe by 2 and both exe and exe2 stay up. why ?
3. like 2, only the passed argument to exe2 is this from the dll. this time none of the processes stays, but r.c count jumps from 1 to 4 (the dll count) in the dll.

so, the problem is how do the r.c done between processes
and in them ? when a process will stay up ?

many thanks,
   Gilad
0
Comment
Question by:gilad111397
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 240 total points
ID: 1410216
An object cannot be terminated or shut down while there are references to it.

Or until all references to an object are released, the object will continue to live.

So there can be a situations where if an object has a reference to another object and that object has a reference to the original object, then they cannot shut down properly. The only way around this is to hard code one of the objects so that when a request to shut down comes in, the object shuts down regardless of the reference count.

Normally, if you have two objects that must do this, it is better to create a third object which is a manager object. The manager object that passes out resource references to the original objects. This way, the objects don't hold reference counts to each other, but to the manager object. Makes shutting down much easier.


0
 

Author Comment

by:gilad111397
ID: 1410217
Ok, suppose we use an object manager which hold two ActiveX exe objects (exe1 and exe2). When exe1 wants to refer exe2, the manager send to it a pointer to exe2. When I assign a smart pointer (IDispatchPtr, for instance) to the argument which was received from the manager (IDispatch *), that's it, the processes will stay up.
What is wrong here ?
0
 

Author Comment

by:gilad111397
ID: 1410218
The smart pointer is defined as global variable.
0
 

Author Comment

by:gilad111397
ID: 1410219
Also, last clarification, I read about CoMarshalInterface, Is it recommended to use it ? if yes, then when I use LPSTREAM, I understand it should be moved to the other process and it would use CoUnMarshalInterface. How do you recommend to send this LPSTREAM ?

thanks a lot.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

705 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

17 Experts available now in Live!

Get 1:1 Help Now