Link to home
Start Free TrialLog in
Avatar of graham_charles
graham_charles

asked on

reference to win.tlb vs. explicit declarations

I recently stumbled across a project that included a reference to win.tlb (the Windows type library), and because of that, didn't require explicit API declarations for a number of things, like SetActiveWindow, many API constants, etc.

Is that a reasonable thing to do? I've always declared the APIs I need explicitly in a code module, but if the declarations already exist in type libraries on every Windows system, it seems safer (?) to include the reference only?

Thanks for any comments.
Avatar of adam8
adam8

Type Libraries are a good way of storing declarations and constants. It is safer because sometimes declarating an API from the decaratiosn section will cause the app to crash when the API is executed, but executing the API from a type library won't cause the program to crash.

I am not saying in all cases, but in some situations you have to declare a specific API in a type library to prevent crashes when the APi is executed.

the type library is compiled into the application so the destination computers don't require the type library.

This is why it is better than using dll files.
ASKER CERTIFIED SOLUTION
Avatar of webJose
webJose

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of graham_charles

ASKER

Wow, I'm convinced! One last question... am I going to have any trouble across different Windows versions, say back to Win95? I know some of these functions have evolved in that time...

Thanks,

g.
Nope, I can't think of a case.  But if you encounter a problem, try with a declare statement and recompile.  If it works, most likely the entry point for the function was changed.