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 / CLR / May 2006

Tip: Looking for answers? Try searching our database.

Late binding to events without typelib?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Davis - 26 May 2006 05:13 GMT
I'm using CLR (VB.NET -- C# and even C++ are options if necessary) to
late-bind to an object at runtime. It's easy to late bind to method and
property members (Dim obj as Object = myObj : Return obj.Name). I don't have
access to any sort of type library, which is why I'm late-binding. Seems to
work fine on these members.

However, I'd like to know if it's possible to sink event handlers to the
same object. VB.NET doesn't seem to automagically support late binding on
events. Is this even possible?

Willing to use any tool (C++ wrapper, etc) if necessary. Please direct me to
a book, resource, tool, or simple advice. Thanks.

Thanks,
Jon
Jon Davis - 26 May 2006 05:19 GMT
Clarification: The events are raised by the COM object. I'm not raising them
to the COM object. I'm trying to handle the COM object's events. Without a
type library, I don't know how.

Thanks,
Jon

> I'm using CLR (VB.NET -- C# and even C++ are options if necessary) to
> late-bind to an object at runtime. It's easy to late bind to method and
[quoted text clipped - 11 lines]
> Thanks,
> Jon
Schmidt - 26 May 2006 16:59 GMT
> Clarification: The events are raised by the COM object.
> I'm not raising them to the COM object. I'm trying to handle the
> COM object's events. Without a type library, I don't know how.
Just write a COM-Wrapper, wich is able to catch the COM-Events
of any desired LateBound-COM-Object(s) - and delegate them from
its central EventHandler-Routine to your Application.

For VB-Classic there are already solutions out there:

You could use my implementation of Eduardo Morcillos
EventCollection (Version 1 + my fixes).
http://www.datenhaus.de/Download/eventcol.zip
(contains an older Version of EdanMos OleLib.Tlb)

of simply use Version 2 of his original implementation (also with Fixes):
http://www.mvps.org/emorcillo/download/vb6/grl_event2.zip

Olaf
Jon Davis - 27 May 2006 07:26 GMT
Signature

Jon Davis

>> Clarification: The events are raised by the COM object.
>> I'm not raising them to the COM object. I'm trying to handle the
>> COM object's events. Without a type library, I don't know how.
> Just write a COM-Wrapper, wich is able to catch the COM-Events
> of any desired LateBound-COM-Object(s) - and delegate them from
> its central EventHandler-Routine to your Application.

Something like that was my intent using .NET's System.Runtime.Interop
namespace but I don't know exactly what I should do here. You and Igor have
given me some hopefully good pointers but it'd be nice if I could get some
additional guidance within the .NET Framework if at all possible.

If not possible, I'll try to make do with what you guys have given.
Unfortunately, I'm obviously not a great COM expert but I'm trying to
grow...

Thanks!!!

Jon
Igor Tandetnik - 26 May 2006 13:29 GMT
> However, I'd like to know if it's possible to sink event handlers to
> the same object. VB.NET doesn't seem to automagically support late
> binding on events. Is this even possible?
>
> Willing to use any tool (C++ wrapper, etc) if necessary.

First, you need to find out the IID of the source interface. If you are
lucky, the object implements IProvideClassInfo2 and you can use
IProvideClassInfo2::GetGUID. Or, the object may implement
IProvideClassInfo, in which case you call
IProvideClassInfo::GetClassInfo and dig through its type library to find
its default outgoing interface.

Once you know the IID, write a COM object that implements IDispatch
(only Invoke method needs to be implemented). Make sure QueryInterface
responds positively when queried for IUnknown, IDispatch and the source
interface IID. Advise the sink to the source via
IConnectionPointContainer / IConnectionPoint interfaces implemented by
the source object.

When an event fires, your implementation of Invoke will be called. At
this point you need to somehow make sense of the parameters.
Signature

With best wishes,
   Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


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.