all groups > dotnet clr > may 2006 >
You're in the

dotnet clr

group:

Late binding to events without typelib?


Late binding to events without typelib? Jon Davis
5/25/2006 9:13:14 PM
dotnet clr: 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

Re: Late binding to events without typelib? Jon Davis
5/25/2006 9:19:18 PM
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


[quoted text, click to view]

Re: Late binding to events without typelib? Igor Tandetnik
5/26/2006 8:29:01 AM
[quoted text, click to view]

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.
--
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

Re: Late binding to events without typelib? Schmidt
5/26/2006 5:59:22 PM

"Jon Davis" <jon@REMOVE.ME.PLEASE.jondavis.net> schrieb im Newsbeitrag
news:%23yxP3uHgGHA.764@TK2MSFTNGP03.phx.gbl...

[quoted text, click to view]
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

Re: Late binding to events without typelib? Jon Davis
5/26/2006 11:26:34 PM


--
Jon Davis

[quoted text, click to view]

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

AddThis Social Bookmark Button