DLL Basics


Since, we are going to be using dll’s to have 1 single copy of our engine code, lets understand the basics of DLL’s. For those of you, who are on the fence of whether to use a dll or not. Here are some of the advantages of using a dll as per MSDN

We will be using __declspec(dllexport) and __declspec(dllimport) to export and import functions, data and objects to and from a dll. We will mainly be using it to export/import functions or interface declarations and not member variables.

I prefer to have a header file which can encapsulate the above function calls. I will explain it with an example

#ifdef project_EXPORTS
#define project_API __declspec(dllexport)
#else
#define project_API __declspec(dllimport)
#endif

 

For the project from which we want to export functions, project_EXPORTS macro will be defined so that project_API automatically map to __declspec(dllexport). For all other projects project_API will map to __declspec(dllimport)

Now for whichever interface, we need to export all/the functions all we need to do is include the above header and add the following code

class project_API className
{
};

This takes care of exporting/importing all the functions, member variables in the class className.

Leave a comment

Your email address will not be published. Required fields are marked *