Dynamic libraries in C++



Dynamic Link Libararies

    "*.dll is missing" is an error that just about every gamer is familiar with. Of course, this error is not only related to games. Just about any application that uses external libraries are subject to this error. 

What this message is saying is that an external library that the application uses just happens to be missing. Well, I'm not going to talk about errors that occur due to missing dll files-or about how to fix those. Rather, I'm going to talk about how those are created, using C++. 

Dynamic libraries are very useful since they have ready made code in them and therefore it makes sense for a programmer to use this. I'm not going to talk about the steps included in the creation of DLL file and walk you through it. Instead, I'm going to go backwards. Let's start. 



This, according to basic c++ knowledge, means that the header from a file called DynamicLib is included, and therefore has it's functions used. The function used here is a function called 'divide', which is what we will be working up on. Now imagine DynamicLib.h and DynamicLib.cpp to be the actual code of the DLL file which, of course, happens to have a method in it that the program was using (called divide, which gives the division of two numbers).   




The two pieces of code above show this 'divide' method where the former is the header file and the latter the cpp file. 

It's that simple. If you build this, you should get a .dll file that holds the method you created. 


There are a few more steps. You still need to say that your program is using this DLL file. To set that up, you need to go to your project settings and configure the linker to link into your DLL file. But that is pretty much all there is to it. 

Comments

Popular Posts