Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2004

Tip: Looking for answers? Try searching our database.

Declaring events in COM built in .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
roy - 23 Oct 2003 00:14 GMT
Hi everyone.
I built in .NET a 'class library' project , which then I
compiled with "Register for COM interop".
I also added some events.

I use this component in VB6, but I can't hook up to the
events.
Can someone please help?

In the .NET component's code, I tried to define events in
     2 different ways:
1."
 public delegate void ClickedEventHandler(string val);
 public event ClickedEventHandler Clicked;
 and then...
 if(Clicked!=null) Clicked(txt.value);
 "

2. [InterfaceTypeAttribute
(ComInterfaceType.InterfaceIsDual)]
    public interface IMonitorEvent
     {
        void HandleMonitorEvent(bool IsEmergency);
     }

Then, in order to hook up to those events in VB6:
1. I added a refernce in VB6 to the component.
2. I created instance
  "
   Dim MyObj As ContainerForIE.Form1
   Set MyObj = CreateObject("ContainerForIE.Form1")
   MyObj.Show
  "
3. I tried to use
  "Public WithEvents MyObj As ContainerForIE.Form1"
  But it raises an error "Object does not source
  automation events"

Can anyone help please?
Girish Bharadwaj - 23 Oct 2003 04:08 GMT
> Hi everyone.
> I built in .NET a 'class library' project , which then I
[quoted text clipped - 37 lines]
>
>  

You need to basically declare an interface, provide a GUID to that
interface, make it IDispatch based and use ComSourceInterfaces() to
assign that interface as the event interface. Then use delegates to
point to the methods exposed by the interface.

If you did not understand what I am talking about, check out MSDN for
"Raising Events handled by COM Sink" topic. In VS.NET 2003 its in,
ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconraisingeventshandledbycomsink.htm
HTH.
Gordz - 28 Jan 2004 21:40 GMT
I know this is a little late of a response, but I'd like to thank you Girish
for pointing me to the Microsoft article which showed how to set up events
in a COM Interop environment.

I've looked everywhere and obviously didn't use the correct keywords when
searching. This is the first example that actually showed the event
declarations and usage.

Regards,

Gord

roy wrote:
> Hi everyone.
> I built in .NET a 'class library' project , which then I
[quoted text clipped - 35 lines]
>
> Can anyone help please?

You need to basically declare an interface, provide a GUID to that
interface, make it IDispatch based and use ComSourceInterfaces() to
assign that interface as the event interface. Then use delegates to
point to the methods exposed by the interface.

If you did not understand what I am talking about, check out MSDN for
"Raising Events handled by COM Sink" topic. In VS.NET 2003 its in,
ms-help://MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconraisingeventshandledbyco
msink.htm
HTH.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.