Creating Engine DLL

Started by
3 comments, last by Nyarlath 15 years, 3 months ago
So I'm looking to break my engine apart to separate it from my game code as it is now. The problem is, I'm not quite sure what and how to move my engine code into the DLL and accompanying .LIB. Any help would be greatly appreciated.
Advertisement
Which IDE/programming environment are you using? MSVC should make it fairly simple to set up a DLL based project. Also if you put an EXE project in the same solution and set the DLL as a 'dependency', then it will automatically link to your LIB file for you.

Most DLL libraries usually define the IMPORT and EXPORT keywords. These keywords, when used in your header files either tell the compiler that this class is being exported by the currently compiling code (e.g. when compiling a DLL), or that it has to be imported (from a DLL) by the currently compiling code (e.g. when compiling a EXE).
#ifdef WIN32 	#define EXPORT __declspec(dllexport)	#define IMPORT __declspec(dllimport)#else	#define EXPORT	#define IMPORT#endif
And then they define a keyword that identifies classes (etc) as being part of your DLL:
#ifdef COMPILING_MY_DLL	#define MY_DLL EXPORT#else	#define MY_DLL IMPORT#endif//Use it like this:MY_DLL class MyClass{...
In the project properties of your DLL, add COMPILING_MY_DLL to the preprocessor definitions. Now the compiler will know that classes marked with MY_DLL have to be exported when compiling the DLL, and have to be imported when compiling an EXE.
Using your example would MY_DLL flag everything as part of the dll if the flag is put in front of the class, or will I need to put that before every function too?
Sorry to bump, but I've got it generating a DLL file.

The only thing is I don't know how to get Visual Studio 2005 to generate the Import Library as well.

Again, any help is greatly appreciated.
Be sure you compile the lib as dynamic library and the applicatiion as exe.
Be sure you put COMPILING_MY_DLL in the preprocessor definitions of the library.
Be sure you add the lib file to the additional dependencies (of linker) of the application (something like "$(OutDir)\Engine.lib").
Be sure the app and the lib have the same output folder.

Here you can download a sample I have built for you.

Hope it helps! ;)

This topic is closed to new replies.

Advertisement