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