473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

1 COM interop event OK, more than 1 event NOT OK in C#

Hi everyone,

I'm writing a C#.net app that is controlling an automation server.
Added a reference to the COM server.
Have the interop wrapper classes generated.

Have the following code to instantiate the COM server and to attach to
the event:

........
obj = new ABCClass();

obj.OnUserClosed += new
ABCClassEvents_OnUserClosedEventHandler(this.ABCUs erClosed);
......

Everything compiles and runs OK.
I'm able to execute methods and access properties of the COM object.
The event handler got called correctly too.

My problem is if I attach more than one events like below:

........
obj = new ABCClass();

obj.OnUserClosed += new
ABCClassEvents_OnUserClosedEventHandler(this.ABCUs erClosed);
obj.OnFormSaved += new
ABCClassEvents_OnFormSavedEventHandler(this.ABCFor mSaved);
......

I will get a COMException during runtime. Now, I have 4 events need to
handle. I have tested each of them. Each works correctly individually
and got called, but I cannot able to attach more than one event. Any
ideas?

Thanks!
Ducky

Nov 16 '05 #1
5 3442
What does the Exception say?
John Puopolo

"ducky" <do*******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi everyone,

I'm writing a C#.net app that is controlling an automation server.
Added a reference to the COM server.
Have the interop wrapper classes generated.

Have the following code to instantiate the COM server and to attach to
the event:

.......
obj = new ABCClass();

obj.OnUserClosed += new
ABCClassEvents_OnUserClosedEventHandler(this.ABCUs erClosed);
.....

Everything compiles and runs OK.
I'm able to execute methods and access properties of the COM object.
The event handler got called correctly too.

My problem is if I attach more than one events like below:

.......
obj = new ABCClass();

obj.OnUserClosed += new
ABCClassEvents_OnUserClosedEventHandler(this.ABCUs erClosed);
obj.OnFormSaved += new
ABCClassEvents_OnFormSavedEventHandler(this.ABCFor mSaved);
.....

I will get a COMException during runtime. Now, I have 4 events need to
handle. I have tested each of them. Each works correctly individually
and got called, but I cannot able to attach more than one event. Any
ideas?

Thanks!
Ducky

Nov 16 '05 #2
It says, "An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
interop.las.dll

Additional information: Exception from HRESULT: 0x80040202.
"

Thank you!

Ducky

Nov 16 '05 #3
Ducky:

See MSDN KB article: Q183216.

It appears that something is happending with the underlying callback
architecture. The IConnectionPoint architecture is the COM way to do
callbacks. You may need to add the connections to the COM object
differently than just using the += operator. Check out the deletages
documentation for more info. I will let you know if I come across
anything as well.

John Puopolo
ducky wrote:
It says, "An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
interop.las.dll

Additional information: Exception from HRESULT: 0x80040202.
"

Thank you!

Ducky


Nov 16 '05 #4
Thank you very much, John!

Nov 16 '05 #5
Hi John,

I have followed the example in :

http://support.microsoft.com/default...b;en-us;308825

instead of using += operator, I'm using:

..............................
UCOMIConnectionPointContainer oConnPointContainer =
(UCOMIConnectionPointContainer) MyComObj;

Guid guid=typeof(ABCComObjEvents).GUID;

oConnPointContainer.FindConnectionPoint(ref guid,out
m_oConnectionPoint);

m_oConnectionPoint.Advise(this,out m_Cookie);

.........................
still no luck for me. It giving me the same exception. I need help :(

Ducky

Nov 16 '05 #6

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

Similar topics

1
by: Iain | last post by:
I raised this a few days ago and Dmitriy helped, but there's been a lot of posts under the bridge since then so I thought I'd start afresh. Basically, I have a COM Dll written in C++ (6). It's...
0
by: Nadav | last post by:
Hi, Introduction: **************** I am writing a component based application, the application is built of several Native COM objects and some .NET classes exposed as COM objects by 'COM...
0
by: Andy Turner | last post by:
I've got an ATL out-of-process COM server, which implements a single CoClass (let's call it MyServer) which I'd like to get events from within a C# front end. I've inserted a reference to the COM...
20
by: Razzie | last post by:
Hey all, I'm really going through a small hell right now - I've completely lost it :) I made a project, using two interop libraries from exchange (created them as in this msdn article:...
0
by: Ollie Riches | last post by:
I am using COM Interop to access and execute a remote DTS package. I have taken the code from the KB article http://support.microsoft.com/kb/319985/EN-US/ and converted this into C#. I have a...
3
by: Stryker.Ninja | last post by:
First time poster, please be gentle :P I am using a third party ocx control in a C# 2.0 application. The interop seems to be working fine except for events. When I try and attach an event, it...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
0
by: frederick.the.fool | last post by:
I'm writing a project that does Visio automation. I'm writing it in C+ +/CLI because it needs to reference a good amount of native C++ code. One way to call the Visio API, of course, is to use...
2
by: JimLad | last post by:
Hi, First of all I didn't design this website, but I have been asked to fix it with the minimum fuss! Website is using .NET on IIS6 with an Excel Interop to produce reports. The website...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.