Advertisement

Making/Using DLLs

Started by June 08, 2000 01:55 PM
4 comments, last by Yanroy 24 years, 6 months ago
I know enough people have posted this question so that I should know the answer, but I don''t. I would like to know two things: What is REQUIRED to put IN a DLL. What (compiler independent) command is used to export functions. If you can''t satisfy the compiler independent part, try to find one that works with MetroWerks CodeWarrior 3.1 PS - One last question (guess I lied about only two things)... Can you use interfaces with DLLs like you would with a normal LIB file? (aka EXACTLY the same) --------------------

You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

It really depends on what you want to use the DLL for.

OK, here's a short overview of library types and usage:


1) STATICLY LINKED LIBRARY

This type of file is compiled directly into the program code. You use this type just to separate parts of a project. It really is no different from including the .cpp files directly. You can use the code inside a static lib by including the headers into your project, and then just calling the functions/classes whatever.

Advantages: You don't have to build a list of exports with this approach, as the header files take over that function.


2) DYNAMICLY LINKED LIBRARY

This type of file is compiled separately from the program code. The advantages of this type are that when bugs occur in the DLL, all you have to do is to overwrite the DLL with a new version, and the program will still work correctly with it. Writing a DLL in this way generates a .lib file, which you link staticly to your EXE. This .lib file contains the function names, a list of exports, etc. that make the DLL work. You can also export classes from the DLL.

Advantages: Splitting up the code into multiple files makes it easier to fix bugs.


3) DYNAMICLY LINKED DYNAMICLY LOADED LIBRARY

This type of file is very special. You must write code to load it into your program manually (in Windows, you use LoadLibrary()/FreeLibrary()). This type of DLL cannot export classes or functions, because you must hard-code all the linking in yourself.

Well, this is how plugins are designed -- they sport all of the same function names, but have different code in them. The program typically uses them by loading the DLLs in one-by-one, and then calling some standard functions to initialize them. The standard functions are whatever you define.

Advanages: You don't have to know before-hand what DLLs you will be using. (P.S. If you want to use this type, I've got a dandy example for wrapping each DLL in a class.)


Actually, you are not required to put any code in a DLL. Just put in whatever code you want. If you want to know what compiler standard keyword there is, I don't think there is any. (I know __declspec(dllexport) in VC, but that's MS-specific.) You'll most likely have to write a .def file for the DLL, which should be well-documented by your compiler's docs.

Good Luck!



- null_pointer
Sabre Multimedia


Edited by - null_pointer on June 9, 2000 8:42:25 AM
Advertisement
By combining what you have posted with the sketchy docs that came with my compiler, I *think* (aka untested) I have gotten runtime loading or whatever its called going. Just one (hopefully) last question: what header do I need to include to use LoadLibrary() and FreeLibrary()? I have tested loadtime linking DLLs and they work... but it would be nice to specify a file name instead of renaming DLLs when I want to change what the program does
--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

Those functions are declared in winbase.h, which should be included by windows.h.


- null_pointer
Sabre Multimedia
If the functionality is not in your main game pipeline, then consider using COM. COM expands on the DLL idea. The Windows operating system arguably manages the COM object better than a standard DLL. They are also fairly easy to create and use in VC++ by using the ATL wizard. On Windows 2000 COM+ also gives you hte ability to group the dll''s by application, start and stop DLLs using MSDTC and provides the interfaces you are looking for. DirectX is written using COM.

Kressilac

ps Beware, you can get into a lot of trouble using COM with respect to speed if you don''t take the time to learn COM.
Derek Licciardi (Kressilac)Elysian Productions Inc.
you do not have to use add the load library code into your program. You can create your dll and compile it.. add the .lib file to your main project along with the the header file that must have the prototypes to your functions.

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

This topic is closed to new replies.

Advertisement