DLL Programmer's Guide for TNS/R Systems
Finding Symbol Definitions
DLL Programmer’s Guide for TNS/R Systems—522203-002
4-14
Example: Intercepting an Exported Symbol
The symbol Gamma, provided by the existing Library D, is intercepted for selected
calling loadfiles (including DLL A). These selected loadfiles must be relinked to put DLL
X in their libLists and remove Library D. Hence, their Gamma references are bound to
the definition in DLL X. The new function that modifies the original Gamma goes into X
and Y, and Y accesses Library D to get the original Gamma function, so you do not have
to rewrite it. Calls to Gamma from unmodified calling loadfiles continue to go directly to
Library D.
To create this library intercept you:
1. Relink the calling modules (such as A) that are to use the intercepted Gamma in
order to replace D in their liblists with X. These calling loadfiles must be localized.
2. Write a new localized DLL X that contains the new (intercept) function and offers
the intercepted symbol, Gamma. Make X re-export D, so the other symbols D
offers are available to the callers.
3. So that you do not have to rewrite the original Gamma definition, the new function
in DLL X needs to pass control to Gamma in DLL D. But DLL X cannot call Gamma
in DLL D directly, because X’s reference to Gamma would be resolved to X’s own
definition of Gamma. Hence, you introduce an intermediary DLL, Y, which
references Gamma. Y must be localized and have D in its liblist. If for some reason
X must be in Y’s liblist, then be sure that D precedes it in that list.
4. Instead of calling Gamma, X calls Joe to pass the information to Y. Y’s definition of
Joe converts this to a call for Gamma in D.
Figure 4-6. Intercepting a Call to Library D
DLL A
Alpha
Beta
Gamma
DLL X
Gamma Joe
VST046.vsd
Library D
Alpha
Beta
Gamma
DLL Y
Joe Gamma