Dynamic Link Libraries Inside-Out - Resource Only DLLs
(Page 6 of 9 )
Usually a dynamic link library would contain many exports that other programs use. However, a DLL may choose not to export even a single function. Why would such a DLL ever be created? The answer is resources and their use in localization.
Let's say you're working on a Windows application that needs to be deployed in many languages. Normally you would write all the menus, static strings in the native language you work in, but what if the application should have a capability to be customizable in terms of the language of operation. One solution could be to make separate resources for each, but that’d take a lot of effort on the developer’s part and obviously not a good solution. Another solution could be to put all the strings and menus etc. that need to be localized are kept in a DLL and you just modify the resources to make it in a different language. And on the users demand choose the appropriate DLL and use those resources in an application. Here comes the use for resource only DLLs.
DLLs and Function Forwarding
You may choose to delegate handling of the functions exported from your DLL (but not implemented) to implementation in some other DLL. This is called function forwarding.
You can do so just by making an entry in your import definition (.def) file which mentions the original function and its ordinal number as:
SCardAccessNewReaderEvent = original.SCardAccessNewReaderEvent @1
This is a function exported by WinSCard.dll. While doing so you’ll need to forward all the functions which the original library exports. It means a lot of work. So you’d ask, “Why do I need something like that?” The answer is if you need to override the default behavior of a few functions of a DLL where you don’t have the source code to it …….. You may use this technique. DLL function hooking is another way which is more complicated, and here are we doing it the simple but hard way. So you just forward all the functions other than you need to override and just rename the original DLL to something like xyz.dll and provide an entry for each overridden and forwarded function. So a function Foo1 overriden and Foo2 forwarded your def file will have the entries like:
Foo1 private @1
Foo2 = xyz.Foo2 @2
And you’re done. Now after doing the processing in your defined Foo1 you may or may not choose to call the xyz.Foo1 function based on your design.
Next: Dynamic Link Library Redirection >>
More Code Examples Articles
More By Digvijay Chauhan