Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Lutfie Ahmad on February 17, 2009, 08:02:39 AM

Title: get event interface with itypelib
Post by: Lutfie Ahmad on February 17, 2009, 08:02:39 AM
Hi,
Im a freebasic programmer, impressed by your TypeLib browser, im following link provided in this forum to make a typelib browser. the syntax between PB and FB seem close. I wrote in my typelib documentation credit to you. but it is with tlb32inf.dll.

then someone inform me that vista dont support tlb32inf.dll, so i must switch to use Itypelib to generate code.
So far, via itypelib, I can make code for vtable and invoke, enum constant, record, union, alias. and module.
but im still have no idea to get event interface via itypelib.

if you dont mind, how to get event interface via itypelib in PB?

thank you.
Title: Re: get event interface with itypelib
Post by: José Roca on February 17, 2009, 04:47:37 PM
Quote
then someone inform me that vista dont support tlb32inf.dll

As far as I know, it only works if you run the application as administrator.

Quote
how to get event interface via itypelib in PB?

To identify event interfaces, if ITypeInfo.GetImplTypeFlags returns 2 or 3 (default event interface), it is an event interface.

The problem is that this information is only available through the CoClass. Therefore, when parsing the type library, if ITypeLib.GetTypeInfoType returns TKIND_COCLASS you have to call ITypeInfo.GetTypeAttr to retrieve a pointer to the TYPEATTR structure and get the number of implemented interfaces looking at the cImplTypes member of this structure. Then you do:


cImplTypes = @pTypeAttr.cImplTypes
FOR x = 0 TO cImplTypes - 1
   lImplTypeFlags = 0
   hr = pITypeInfo.GetImplTypeFlags(x, lImplTypeFlags)
   pRefType = 0
   hr = pITypeInfo.GetRefTypeOfImplType(x, pRefType)
   hr = pITypeInfo.GetRefTypeInfo(pRefType, pImplTypeInfo)
   hr = pImplTypeInfo.GetDocumentation(-1, bstrName, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
   IF lImplTypeFlags = 2 OR lImplTypeFlags = 3 THEN    ' // Events interface / Default events interface
      ' Store the name of the event interface for later use
   END IF
NEXT

Title: Re: get event interface with itypelib
Post by: Lutfie Ahmad on February 18, 2009, 01:39:38 AM
thank you :)
I found some snippet in C, but their syntax beyond my understanding :-(
/* So we've got the dispatch interface; lets list the event methods */
for (i = 0; i < attr->cFuncs; i++) {
zval *tmp;
DISPID lastid = 0; /* for props */
int isprop;

if (FAILED(typeinfo->lpVtbl->GetFuncDesc(typeinfo, i, &func)))
break;

isprop = (func->invkind & DISPATCH_PROPERTYGET || func->invkind & DISPATCH_PROPERTYPUT);

if (!isprop || lastid != func->memid) {


with your snippet I can move again :-)
I hope you will please to help me, when Im here again with question
Title: Re: get event interface with itypelib
Post by: José Roca on February 18, 2009, 01:46:19 AM
 
The C code that you have posted is meant to retrieve information about the name and parameters of the methods. Mine is to identify which interfaces are event interfaces. Not sure if that is what you wanted.
Title: Re: get event interface with itypelib
Post by: Lutfie Ahmad on February 18, 2009, 01:50:58 AM
aaah, lucky me, im not translated this code, i just stick to this quote
Quote/* So we've got the dispatch interface; lets list the event methods */
your code is what I wanted :-)
Title: Re: get event interface with itypelib
Post by: Lutfie Ahmad on February 20, 2009, 02:07:49 AM
Hi Jose,
if you interrested, here is the result of your TLB clone for fb ^_^
http://fbedit.freebasic.net/viewtopic.php?f=6&t=196&start=10 (http://fbedit.freebasic.net/viewtopic.php?f=6&t=196&start=10)

its not finished yet, but the generated code are usable in freebasic, Im still in working to finishing and finding bugs.
Title: Re: get event interface with itypelib
Post by: José Roca on February 20, 2009, 02:21:08 AM
 
Thanks for letting me know. Writing a COM browser is the best way to learn all the secrets of low-level COM programming.