473,692 Members | 3,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disposing Com+ Object

Hey,
I have a C# assembly that inherits from ServicedCompone nt and is
installed in the Com+ with ServerActivatio n.
And I have a C++ application that calls this Com+ object successfully,
But the problem is that I cant seem to dispose the object!

I tried calling the following code:
myComPlus->Release();
myComPlus = NULL;
delete myComPlus;
CoUninitialize( );

The reason I posted it here (DotNet group) is that the same code works
when the Com+ object is NOT a DotNet Assembly.

Apparently I need to find a way to the ServicedCompone nt.DisposeObjec t
from the C++ code!
Is there a way to dispose a .Net assembly from the Com+ by C++ Code?
Thanks ahead

sternr

Jan 9 '06 #1
10 3938

"sternr" <St****@gmail.c om> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
| Hey,
| I have a C# assembly that inherits from ServicedCompone nt and is
| installed in the Com+ with ServerActivatio n.
| And I have a C++ application that calls this Com+ object successfully,
| But the problem is that I cant seem to dispose the object!
|
| I tried calling the following code:
| myComPlus->Release();
| myComPlus = NULL;
| delete myComPlus;
| CoUninitialize( );
|
| The reason I posted it here (DotNet group) is that the same code works
| when the Com+ object is NOT a DotNet Assembly.
|
| Apparently I need to find a way to the ServicedCompone nt.DisposeObjec t
| from the C++ code!
| Is there a way to dispose a .Net assembly from the Com+ by C++ Code?
| Thanks ahead
|
| sternr
|

You have to call Dispose() explicitely.

Willy.
Jan 9 '06 #2
You need to show more information. First, can you show some of the
code?

In the C++ client, you need to only call Release, and it should release
the object.

On the .NET side, if you are using JIT activation (which is
automatically set if you are using transactions), then you have to make sure
you apply the AutoComplete attribute to your methods on the object which are
exposed. Either that, or you have to make sure that you set the
DeactivateOnRet urn property on the ContextUtils class to true, to indicate
that the object should be deactivated.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"sternr" <St****@gmail.c om> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hey,
I have a C# assembly that inherits from ServicedCompone nt and is
installed in the Com+ with ServerActivatio n.
And I have a C++ application that calls this Com+ object successfully,
But the problem is that I cant seem to dispose the object!

I tried calling the following code:
myComPlus->Release();
myComPlus = NULL;
delete myComPlus;
CoUninitialize( );

The reason I posted it here (DotNet group) is that the same code works
when the Com+ object is NOT a DotNet Assembly.

Apparently I need to find a way to the ServicedCompone nt.DisposeObjec t
from the C++ code!
Is there a way to dispose a .Net assembly from the Com+ by C++ Code?
Thanks ahead

sternr

Jan 9 '06 #3
Willy - There is no Dispose method, do you mean I need to implement
IDisposeable?
Nicholas - In the managed code I dont use any of the Com+ features - no
Object Pooling,JITA or Transactions...
And as for the C++, here's the full code:

MULTI_QI mqi;
HRESULT hr;
CLSID cls;
objComPlus::IMy Cls* objCom;
COSERVERINFO cs;
ZeroMemory(&mqi ,sizeof(mqi);
cs.pAuthInfo=NU LL;
mqi.pIID = &__uuidof(objCo mPlus::_MyCls);
mqi.pitf=objCom ;
mqi.hr=0;
hr=CoInitialize (NULL);
if (SUCCEEDED(hr))
{
hr=CLSIDFromPro gID(OLESTR("obj ComPlus.MyCls") ,&cls);
if (SUCCEEDED(hr))
{
mqi->QueryInterface (__uuidof(objCo mPlus::_MyCls), (void**) &objCom);
/*
..
Call some methods from objCom
..
*/
ht=CoDisconnect Object(objCom,0 ); // This line isnt needed but it doesnt
hurt trying
objCom->Release();
objCom=NULL;
delete objCom;
CoUninitialize( );
}
}

Hope this helps!
Thanks again for your help!

sternr

Jan 9 '06 #4
sternr,

First, if you are not using any of the COM+ features, then why are you
using COM+? You shouldn't use it at all, since you can expose your object
to COM without it being hosted in COM+. Is it because you want it hosted on
another machine?

As for your code accessing the object, it doesn't make much sense.
First, you care not showing the call to create the object, and why you need
a MULTI_UI structure for multiple interfaces (especially since you are using
just one, it would seem).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"sternr" <St****@gmail.c om> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Willy - There is no Dispose method, do you mean I need to implement
IDisposeable?
Nicholas - In the managed code I dont use any of the Com+ features - no
Object Pooling,JITA or Transactions...
And as for the C++, here's the full code:

MULTI_QI mqi;
HRESULT hr;
CLSID cls;
objComPlus::IMy Cls* objCom;
COSERVERINFO cs;
ZeroMemory(&mqi ,sizeof(mqi);
cs.pAuthInfo=NU LL;
mqi.pIID = &__uuidof(objCo mPlus::_MyCls);
mqi.pitf=objCom ;
mqi.hr=0;
hr=CoInitialize (NULL);
if (SUCCEEDED(hr))
{
hr=CLSIDFromPro gID(OLESTR("obj ComPlus.MyCls") ,&cls);
if (SUCCEEDED(hr))
{
mqi->QueryInterface (__uuidof(objCo mPlus::_MyCls), (void**) &objCom);
/*
.
Call some methods from objCom
.
*/
ht=CoDisconnect Object(objCom,0 ); // This line isnt needed but it doesnt
hurt trying
objCom->Release();
objCom=NULL;
delete objCom;
CoUninitialize( );
}
}

Hope this helps!
Thanks again for your help!

sternr

Jan 9 '06 #5
Hey Nicholas,

I want to use Com+'s features but for testing purposes I'm not using
any of them...
And about the MULTI_UI - my object has multiple interfaces, I didn't
show use of them because it's not related to my problem...

I'm pretty sure the problem lies in disposing managed Com+ from C++
code as a hole and not in my particular piece code - since the same
code works for unmanaged Com+ objects...

sternr

Jan 9 '06 #6
If your COM+ class is holding unmanaged resources, you should implement
IDisposable if you want deterministic clean-up of these resources, after all
it's a managed class so .NET design guidelines apply here. Else your object
life time and the resource clean-up is dictated by the GC.
Note that calling Release on the object interface from unmanaged code should
make the object available for GC collection, but again this is something
that happens at some point in time (non-deterministical ly).

Willy.

"sternr" <St****@gmail.c om> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
| Willy - There is no Dispose method, do you mean I need to implement
| IDisposeable?
| Nicholas - In the managed code I dont use any of the Com+ features - no
| Object Pooling,JITA or Transactions...
| And as for the C++, here's the full code:
|
| MULTI_QI mqi;
| HRESULT hr;
| CLSID cls;
| objComPlus::IMy Cls* objCom;
| COSERVERINFO cs;
| ZeroMemory(&mqi ,sizeof(mqi);
| cs.pAuthInfo=NU LL;
| mqi.pIID = &__uuidof(objCo mPlus::_MyCls);
| mqi.pitf=objCom ;
| mqi.hr=0;
| hr=CoInitialize (NULL);
| if (SUCCEEDED(hr))
| {
| hr=CLSIDFromPro gID(OLESTR("obj ComPlus.MyCls") ,&cls);
| if (SUCCEEDED(hr))
| {
| mqi->QueryInterface (__uuidof(objCo mPlus::_MyCls), (void**) &objCom);
| /*
| .
| Call some methods from objCom
| .
| */
| ht=CoDisconnect Object(objCom,0 ); // This line isnt needed but it doesnt
| hurt trying
| objCom->Release();
| objCom=NULL;
| delete objCom;
| CoUninitialize( );
| }
| }
|
| Hope this helps!
| Thanks again for your help!
|
| sternr
|
Jan 9 '06 #7
But if my client was a .Net application, I could'v called
ServicedCompone nt.DisposeObjec t and force
The Com+ object to be disposed!
Isn't there a way to copy the behaviour of the DisposeObject method to
my C++ application, or maybe call COM wrapper for EnterpriseServi ces so
that I could call directly the DisposeObject?
Thanks again

sternr

Jan 9 '06 #8

"sternr" <St****@gmail.c om> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
| But if my client was a .Net application, I could'v called
| ServicedCompone nt.DisposeObjec t and force
| The Com+ object to be disposed!
| Isn't there a way to copy the behaviour of the DisposeObject method to
| my C++ application, or maybe call COM wrapper for EnterpriseServi ces so
| that I could call directly the DisposeObject?
| Thanks again
|
| sternr
|

No there isn't, don't forget that you are at the unmanaged side, so you are
in reality talking to a CCW, while calling into a managed COM+ application
from managed talks through a RCW (and DCOM) to access the COM+ server hosted
class.

Note also this:
From the docs....

It is preferable to use the Dispose design pattern rather than
DisposeObject.

Realy, keep your managed classes consistent with the Dispose pattern, it
doesn't matter whether they are called from managed or unmanaged, you have
to explicitely call Dispose().

Willy.


Jan 9 '06 #9
Hey Willy,
In continue to what you said, I exposed the Dispose void in the Managed
Com+ object,
and inside this void I call - base.Dispose(tr ue).
But when I try to call this new method from my C++ application, I get
an access violation...
Any idea?
Thanks,

sternr

Jan 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3728
by: Chris Capel | last post by:
I've heard a lot of talk on the forum about memory managment in .NET and disposing things, finalizing them, garbage collection, etc. My question is which managed types need to be disposed after being used, and for which is it OK to simply let the garbage collector do its work, without worrying about calling Dispose? Is there a general rule that most don't need to be explicitly disposed, with an exception here and there? Or the other way...
4
1479
by: MC D | last post by:
Question: If I have a class which has a property which is a collection of widget objects (an arrayList of widgets), and both the containter class and the widget class implement the IDisposable interface, does the container class need to call the dispose method of each of the widgets when its dispose method is called, or does this happen automatically because the container class will go "out of scope"? Thanks for any help!
13
4254
by: MuZZy | last post by:
Hi, Just wanted to make sure i get it right: consider this class: // =========== START CODE ============= class Test { private SqlConnection con = null; public void Connect() { con = new SqlConnection(SomeConnectionString);
4
1388
by: sunitabalakrishna | last post by:
Hi, Could someone explain me if I need to implement the Dispose pattern on managed objects that hold objects which have longer life or is a singleton? Example - Class A holds Class Global where Class Global is a singleton. So should Class A have
5
1519
by: Chris | last post by:
I have a form that requires drawing custom lines on it. The color of the lines is suppose to be the same as the forcolor of the form. Am I doing this the most efficent and correct way? Thanks.... Protected mPen As Pen Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) If mPen Is Nothing Then mPen = New Pen(Me.ForeColor)
0
1524
by: Gman | last post by:
Hi, Objective: Draw a grid on a bitmap and set this as a panel's image. (Rather than draw the grid directly on the panel and redraw repeatedly in the paint event.) Problem: It works fine. I'm just not sure about disposing of the objects. I've tried a variety of approaches but I find that when I redraw repeatedly
4
1392
by: Rob | last post by:
Hi all, I wrote myself a little function to do my own housekeeping, I can call it by using Dispose(object) Within this function there's a select case statement which will then, based on some flags and the type of the object do things like close connections, dispose of the object where appropriate and so on.
8
8996
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx http://www.codeproject.com/managedcpp/garbage_collection.asp - sources
29
2371
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but what is an unmanaged resource? Does everything need disposing? I've been using Webrequest, Webresponse, Streamreaders etc. How can I be sure of what needs disposing? Do these get automatically get disposed of at the end of the procedure...
0
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8549
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8814
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7642
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5823
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.