Click to See Complete Forum and Search --> : Loading LIB Files From Functions


Notsosuperhero
July 31st, 2005, 02:00 AM
How can I load a LIB file from a function?

Lets say I have a class CClass with a function called LoadLib(), and I have a LIB file called CLib.lib, how could I load that from th file

SuperKoko
July 31st, 2005, 06:15 AM
LIB files are designed for static linking. Their format is not easy to read, so you should not try to link to LIB files, except if you are writing a linker.

Instead, you should create a DLL which allows dynamic linking at startup time, or at run time (with LoadLibrary and GetProcAddress, and FreeLibrary).
You can:

Change the project options of your LIB files, and set them to DLL (if you use an IDE).
If you use a command line compiler, there is surely a linker option (read the doc of your compiler) to specify the linking target model (you should set it to Win32 PE DLL).
If you have only the binary file of this LIB file, you should write a DLL linked to this LIB file, and exporting needed classes and functions by specifying the correct symbols in the .DEF file (easy if you only export functions).
Since a class contains many mangled symbols, you may write a function CreateCClassInstance, and a function DeleteCClassInstance in the wrapper DLL, and export these functions. If the class is derived from a pure abstract base class containing only pure virtual functions, you can use this interface to manipulate the objects, so you don't need to import symbols to use the object.
If this class contaings non-virtual functions, you may need to write a wrapper class in the wrapper DLL.

Notsosuperhero
July 31st, 2005, 01:45 PM
Thanks for the reply, just before I read it I said to myself "maybe I should just make a DLL"

Siddhartha
July 31st, 2005, 02:44 PM
I said to myself "maybe I should just make a DLL"Read this post (http://www.codeguru.com/forum/showthread.php?p=1137109#post1137109) to see documents that explain -


Forms of Dynamic Linking
Using a DLL
Sample