PC Review


Reply
Thread Tools Rate Thread

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

 
 
ducky
Guest
Posts: n/a
 
      8th Feb 2005
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

 
Reply With Quote
 
 
 
 
John Puopolo
Guest
Posts: n/a
 
      8th Feb 2005
What does the Exception say?
John Puopolo

"ducky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
ducky
Guest
Posts: n/a
 
      8th Feb 2005
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

 
Reply With Quote
 
jpuopolo@mvisiontechnology.com
Guest
Posts: n/a
 
      10th Feb 2005
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


 
Reply With Quote
 
ducky
Guest
Posts: n/a
 
      10th Feb 2005
Thank you very much, John!

 
Reply With Quote
 
ducky
Guest
Posts: n/a
 
      10th Feb 2005
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

 
Reply With Quote
 
New Member
Join Date: Feb 2006
Posts: 1
 
      13th Feb 2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event ID: 1003, Event Type: Error ,Event Source: System Error,Event Category: (102) BoazBoaz Windows XP General 0 21st Jun 2006 05:39 PM
After Save Event (Interop) Jörgen Ahrens Microsoft Excel Programming 4 20th Feb 2006 07:58 AM
worksheet change event with .NET interop =?Utf-8?B?c3RhdnJv?= Microsoft Excel Programming 0 16th Jun 2005 05:57 PM
I need to clear temporary the event sinks from another event and then restore them, but I don't know which methods signed up for that event Serge Shimanovsky Microsoft Dot NET Framework Forms 14 7th Feb 2005 08:48 PM
Com Interop Event blocked by WaitOne Iain Microsoft C# .NET 6 12th Dec 2003 09:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:08 AM.