🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Creating/Using DLLs

Started by
1 comment, last by Yanroy 24 years, 5 months ago
My compiler (CodeWarrior 3.1) allows me to make a project that is a DLL. If I do this, write some code, and compile it, will it make a DLL that I can then use in some other program? If so, how do I load it? I got this idea from another post, and I haven''t been able to stop thinking about it... can I call ANY function that was in the DLL from the other app? That could mean a solution to a very tough AI problem I have been working on... AI that you could plug in as a separate file. www.trak.to/rdp

Yanroy@usa.com

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

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

Advertisement
In order to use a DLL, you need to either explicitly load it through LoadLibrary. Then you call functions to return the dll function pointers by name, and perform your calls off the function pointers. Or you need to specify the dll at compile time in your exe by including it''s header and import library.
If you are using AI that is pluggable, it''s probably best (easiest) just to link in the import library. When you compile the DLL, it should generate a .lib file too. Link that into the project that uses the DLL, and include a header file with function declarations for all the functions you use in the DLL in all the files you need. That way, you have an easy way to make the functions you use accessable through the DLL. This is only useful if you plan on having the same function name to call in every DLL you make. If not, you have to dynamically load the DLLs.
This is how you would declare the functions (I think):

in the DLL:
extern "C" _declspec(dllexport) void FunctionName(params);

in the program:
extern "C" _declspec(dllimport) void FunctionName(params);

of course, you could still return any type. The better solution would be to have one header file, and in the top of it type:
#ifdef _DLL_
#define EXPORT_TYPE dllexport
#else
#define EXPORT_TYPE dllimport
#endif

then you could just declare the functions as
extern "C" declspec(EXPORT_TYPE) void FunctionName(params);

Hope this helps..


------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge

This topic is closed to new replies.

Advertisement