Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / June 2007



Tip: Looking for answers? Try searching our database.

Enumerating Event Interfaces using TLBINF32.DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alok - 01 Jun 2007 20:18 GMT
I have been trying to automate various sorts of code creation. I have
been using the TLI (TLBINF32.DLL) to query dlls for their contents.
One problem is to identify event exposing classes, and the details of
the events themselves, in the dll. The best solution that I have found
is to call TLI.TypeLibInfoFromFile to get the typelibinfo, then loop
over the TypeInfos to find ones of kind TKIND_COCLASS, and then
checking to see if DefaultEventInterface is not nothing. This seems to
work in a few test cases, but I am worried about what might happen if
there is more than one event interface.

My question is this: How does VB denote that a particular interface
within a coclass is an event interface? I haven't been able to find
this out from the TLI.

Thanks,
Alok
Ken Halter - 01 Jun 2007 20:26 GMT
>I have been trying to automate various sorts of code creation. I have
> been using the TLI (TLBINF32.DLL) to query dlls for their contents.
[quoted text clipped - 12 lines]
> Thanks,
> Alok

This may help... it has a bug or two, but not related to TLB inspection.

ActiveX Documenter
http://www.vbaccelerator.com/home/VB/Utilities/ActiveX_Documenter/article.asp

If you actually want to run it, be sure to read and grab everything in the
Required References section of the download page. Basically, what's
'required' is his subclasser and a TLB file that allows access to otherwise
hidden interfaces.

Signature

Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm

Alok - 01 Jun 2007 21:07 GMT
On Jun 1, 3:26 pm, "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com>
wrote:

> >I have been trying to automate various sorts of code creation. I have
> > been using the TLI (TLBINF32.DLL) to query dlls for their contents.
[quoted text clipped - 25 lines]
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> In Loving Memory -http://www.vbsight.com/Remembrance.htm

This looks interesting.. on preliminary inspection, the event
interface detection happens in  frmDocHelp.pbGetTypeLibInfo, on the
following lines:

           iDefaultEvents
= .TypeInfos(iTypeInfo).DefaultEventInterface.TypeInfoNumber
           If (Err.Number = 0) Then
              m_tDefaults(iTypeInfo).iDefaultEvents = iDefaultEvents
+ 1
           Else
              m_tDefaults(iTypeInfo).iDefaultEvents = -1
           End If

This is pretty clear in that it relies upon the DefaultEventInterface
property. Perhaps I am being paranoid worrying about other event
interfaces - here is my reasoning

1) Declaring things WithEvents is the only way to recieve events in VB
2) The only things that can be declared "WithEvents" are coclasses
3)  The default event interface is the one that you listen to when you
declare something "WithEvents"

it logically follows

4) in order for an event interface to be accessed within vb, it must
be the DefaultEventInterface for some co-class.

Sound correct? It would still be nice to know if event interfaces are
marked in some special way- in a sense they must be, for how does
defaulteventinterface know which one to return?

Alok
Ken Halter - 01 Jun 2007 22:20 GMT
> it logically follows
>
[quoted text clipped - 6 lines]
>
> Alok

Well... I've never looked that closely. I imagine you can find that info in
a book called "Advanced Visual Basic 6", since it was written by a member of
the VB design team and the same guy's the one that wrote tlbinf32.dll, so,
if anyone knows, it's him. His email address is on the site below as well.
He used to post to these groups all the time, but has since moved on to
"bigger and better things" after leaving MS.

http://www.powervb.com/

Signature

Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm

Ralph - 02 Jun 2007 16:35 GMT
> << <snipped>
>
[quoted text clipped - 6 lines]
> marked in some special way- in a sense they must be, for how does
> defaulteventinterface know which one to return?

I second Ken's advice. Get the book.

As for the mystery of the *default*eventinterface. It helps to understand
that the idea of a "default" interface is kind of a VBish thing. eg. The
Public Interface presented by a VB Class is often called the "Default" - but
it is simply the one you get when you declare a reference to the class and
not to any other 'named' interface.

Events are supported by IConnectionPoint/s  They are exposed through an
IConnectionPointContainer which contains two functions - FindConnectionPoint
and EnumConnectionPoints. The "default" is simply the first one or the only
one available.
When seeking a specific IConnectionPoint it's back to 'names' (your
'marks').

Naturally this is a 40,000 foot view.

hth
-ralph
Alok - 06 Jun 2007 22:57 GMT
> I have been trying to automate various sorts of code creation. I have
> been using the TLI (TLBINF32.DLL) to query dlls for their contents.
[quoted text clipped - 12 lines]
> Thanks,
> Alok

I think I've figured out the answer, here's the gory details courtesy
of the  help file tlbinf32.chm (which itself is not that easy to come
by):

Both the DefaultInterface and DefaultEventInterface are actually
members of the Interfaces collection. To determine which interfaces to
use as defaults, TLI walks the interfaces collection and checks the
AttributeMask property. DefaultInterface is the first interface with
the IMPLTYPEFLAG_FDEFAULT flag set (or the first one without
IMPLTYPEFLAG_FSOURCE, if no default is specified). The
DefaultEventInterface has IMPLTYPEFLAG_FSOURCE set, and is either the
first source interface encountered or the first with the
IMPLTYPEFLAG_FDEFAULT or IMPLTYPEFLAG_FDEFAULTVTABLE flags set. For
more explicit control over which interface is considered default, you
can walk the Interfaces collection in code.

It thus appears that I need to look at the interface attributemask,
which should contain combinations of the above flags. The values of
these flags are sort of documented here
http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.comtypes
.impltypeflags(vs.80).aspx

. It makes the head spin a little.
 
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



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