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

D

ducky

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.ABCUserClosed);
......

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.ABCUserClosed);
obj.OnFormSaved += new
ABCClassEvents_OnFormSavedEventHandler(this.ABCFormSaved);
......

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
 
D

ducky

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
 
J

jpuopolo

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
 
D

ducky

Hi John,

I have followed the example in :

http://support.microsoft.com/default.aspx?scid=kb;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
 
Joined
Feb 13, 2006
Messages
1
Reaction score
0
Hi all,

In my project, I have a COM Server with 2 events. I want to solve the same problem on VS2005, but I got another exception ("Specified cast is not valid.”) on this line "m_oConnectionPoint.Advise(this,out m_Cookie);" during runtime.
How should I do it?

Thanks,
levinp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top