> I read somewhere that it would make a difference, maybe it was McKinney.
> Then there is the difference about VB and VBA, VBA being un-compiled.
> My main use will be in VBA. Would that make a difference.
> Final answer will be testing it out and I am not far off doing that.

Signature
----------------------------------------------------------------------
Thorsten Albers albers(a)uni-freiburg.de
----------------------------------------------------------------------
> Since both are resolved at compile time there
> shouldn't be any difference in performance.
But I have definitely noticed a performance gain in VBA. So, moving all
Declares
and structures and enums and constants to a .tlb speeds up startup time of
the VBA project.
> - Declare statements are more flexible in that they allow a declaration
> "As Any"
.tlb can do that as well by declaring as void in the .tlb.
> which allows different Declare statements for the same external procedure
> in one project
> (e.g. different SendMessage() declarations)
Can do that with a .tlb as well.
> prefer Declare statements because they are so easy to edit.
With the TypeLib editor from Matthew Curland it is very easy as well. It
really is a good bit
of software.
As you say pro's and con's and still not sure what the best way is. As I
have done the hard work now
and made the .tlb for all my 140 or so API's plus related structures etc. I
think I will stick with it.
RBS
> RB Smissaert <bartsmissaert@blueyonder.co.uk> schrieb im Beitrag
> <uiJK2tZ0IHA.1240@TK2MSFTNGP02.phx.gbl>...
[quoted text clipped - 24 lines]
> Which one to use depends on nothing else but your personal preferences. I
> myself prefer Declare statements because they are so easy to edit.
> RB Smissaert <bartsmissaert@blueyonder.co.uk> schrieb im Beitrag
> <uiJK2tZ0IHA.1240@TK2MSFTNGP02.phx.gbl>...
[quoted text clipped - 7 lines]
> interpreter/compiler. Since both are resolved at compile time there
> shouldn't be any difference in performance.
One difference comes from the fact that behind the scene VB sets up the
'call' differently for a Declare Directive compared to a TypeLib definition.
For example, it does a runtime check on the parameters for a Directive, but
not for a Typelib.
Another, (which is likely why start-up is a bit quicker for a TypeLib) is
that VB for a directive needs to do a text search on the export list to find
the offset/progid/etc, where with Typelib all that is already provided.
> The main differences are:
> - It is much easier to edit a Declare statement than a type library
> - A type library entry is of project global scope; Declare statements may
> be used with module global scope which allows different Declare statements
> for the same external procedure in one project (e.g. different
> SendMessage() declarations)
I don't consider either of these to be a benefit for a major project. <g>
True. Declare statements can be changed easily during normal editing, but
this also makes it is easy to accidently (or deliberately) insert variations
at different locations. This IMHO is a prescription for trouble.
One can easily provide multiple TypeLibs (yech! But possible. <g>), ie:
JunkStrAPI.Routine()
JunkLngAPI.Routine()
or what I prefer:
JunkAPI.RoutineStr()
JunkAPI.RoutineLng()
A typelib, on the other hand, is essentially 'hidden' away during
development and only modified through a specific process. (ie, I treat IDLs
and TypeLibs as separate projects and track through VSS.)
Using a typedef for the WinAPI or any other common libraries will insure
consistent results (ie, no surprises) across modules, components, and
suites.
> - Declare statements are more flexible in that they allow a declaration "As
> Any"
While it often makes the more deterministic among us to squirm a bit - "As
Any" has been a ghod-send on occasion. <g>
[Note: a Declare directive will over-ride any Typelib definition.]
> - Type libraries are more flexible in that they allow also the definition
> of data types, structures, etc. which is not possible with declare
> statements, and in that they allow to use data types which are not known to
> VB.
Definitely agree with that.
> Which one to use depends on nothing else but your personal preferences. I
> myself prefer Declare statements because they are so easy to edit.
Certainly agree with that.
I would also add:
A Declare statement takes a minimum of 16 bytes each, and usually a lot
more. Typelibs add no overhead to the finished product. [This was probably a
consideration once upon a time, but in this day of gigabyte applications - I
doubt the 'size' overhead would ever be noticed. <g>]
A Declare statement causes the addition of extra code to do parameter
checking at runtime. With a typelib VB will do type checking during
syntax-checking, before the compile. Again no extra overhead in the released
version. And you get Intellisense. With a Declare statement there is no
Intellisense. Many errors are not discovered until runtime.
-ralph
Jim Mack - 20 Jun 2008 12:41 GMT
> One can easily provide multiple TypeLibs (yech! But possible. <g>),
> ie: JunkStrAPI.Routine()
> JunkLngAPI.Routine()
> or what I prefer:
> JunkAPI.RoutineStr()
> JunkAPI.RoutineLng()
It's easy to provide several aliases for the same entry point using a
TLB. You don't need multiple TLBs for that (assuming you know the
ordinal).
> While it often makes the more deterministic among us to squirm a
> bit - "As Any" has been a ghod-send on occasion. <g>
> [Note: a Declare directive will over-ride any Typelib definition.]
Not sure what your point is here, but As Any is certainly possible in
a TLB using void *. And you have to be careful when overriding a TLB
entry, because you can do things in a TLB that you can't in a Declare
(e.g. BSTR/LPSTR).
Which brings up another benefit of TLBs -- one of the biggest, IMO.
You can directly access the -W versions of APIs without StrPtr hoops
(full type checking). Unicode access to the WinAPI (and your own
functions) can give a big performance boost in many cases.
One odd restriction in a TLB, and this is a VB problem only, is that
you can't #define a constant As Double. It gets completely wacked by
VB. So, no Pi for you.
> And you get Intellisense. With a
> Declare statement there is no Intellisense. Many errors
> are not discovered until runtime.
You don't get Intellisense with your Declares? I do...?
--
Jim Mack
MicroDexterity Inc
www.microdexterity.com
Ralph - 21 Jun 2008 18:48 GMT
> > One can easily provide multiple TypeLibs (yech! But possible. <g>),
> > ie: JunkStrAPI.Routine()
[quoted text clipped - 30 lines]
>
> You don't get Intellisense with your Declares? I do...?
All good points.
My "multiple TypeLibs" comment was purely flippant and not meant to be taken
that seriously, only addressing an implication of separate 'api sets'.
As for an Intellisense. I wasn't very clear and deserve to be taken to task.
(My only excuse is the time of posting.)
What I was trying to convey was more related to the convenience of
Intellisense during development, which is just a repeat of what I already
had said.
If I reference a typlib - bang I got Intellisense for all the methods along
with a help string (viewable in Object Browser).
If I use Declares I only get Intellisense for the Declare statement, in
scope, that I typed in. If I make a mistake with the Declare - I get
'mistaken' Intellisense.
In other words - sure I get something that puts up while I type - but it
will only be what I already typed before? The only thing Intellisense does
in that case is insure I'm consistently wrong. <g>
As for the "As Any" comment. That is perhaps more supersition than anything
else. "Void *" while functionally equivalent to my mind as well, but,
(purely anecdotal) while playing around with writing a Type Library I have
found it to fail, while using a Declare with "As Any" worked until I found a
data type both parties could agree on.
Anyway, there's my excuse, but all your admonishments are justified. <g>
-ralph
> RB Smissaert <bartsmissaert@blueyonder.co.uk> schrieb im Beitrag
> <uiJK2tZ0IHA.1240@TK2MSFTNGP02.phx.gbl>...
[quoted text clipped - 21 lines]
> Which one to use depends on nothing else but your personal preferences. I
> myself prefer Declare statements because they are so easy to edit.
Calls in a TypeLib can also be used from another thread when doing "evil
things" :)
In may case, it was an asynch callback from WinInet when I need to reset
an event and close a few handles.

Signature
Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team
iCode Systems