Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Creating a DLL with Code::Blocks

Author
Message
Chris66
15
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 11th Mar 2010 10:31 Edited at: 11th Mar 2010 14:01
Hi all,

I based my work on the clever use of the string tables that Pharoseer discribed in his post "Making a DLL with C++ Express" : http://forum.thegamecreators.com/?m=forum_view&t=165006&b=18

I reduced as possible the steps needed to create a DLL using Code::Blocks (MinGW compiler).

I won't write a full tutorial, The GameCreators already did it, so before to go further please read carefuly The Third Party Commands topic you'll find into the help file of DBP (Technical Documents Section).


So, I assume you are familiar with the process and the explanations regarding the creation of a DLL using Visual C++ ; things are a bit different using Code::Blocks but it will be quite easy using the following steps :

(Note : for this example I used the last official version of Code::Block v8.02 including MinGW)


1) Create a DLL project

- Launch Code::Blocks
- Click on "Create a New Project"
- Click on "Dynamic Link Library"
- Let's give a name to our DLL project e.g. "TestDLL" (a new folder with the same name will be created into the Code::Blocks' Projects folder)
- Click on "Next" then "Finish" buttons to complete the project creation.

Now the "Projects" tab displays the name of our project ("TestDll") with 2 items : "Sources" and "Headers"


You'll notice that the Wizard's DLL creation tool has created some code as a default example, but let's make our own instead :

- Open the "Headers" tree then Right Click on the file named "main.h" and select "Remove file from project" : the "Headers" tree has been removed.
- Open The "Sources" tree and edit the "main.cpp" to remove all the code ((CTRL+A) then DELETE). Now we have got a blank page.


2) Write some functions in our DLL

Copy the code below (which contains 2 simple fonctions) in our "main.cpp" file.

main.cpp



3) Configure the project's properties to create a .DEF file

This file will allow us to get automatically the complete list of the functions of the DLL in their decorated form.

- In the "Projects" tab, Right Click on the project name "TestDLL" and select "Properties..."
- Click on the "Build targets" tab and check that the option "Create .DEF exports file" is selected.
- When done click on the "OK" button to proceed.


4) Build our DLL (CTRL+F9)

The DLL we created can't be used "as this" from DBP but this step will help us to obtain complementary informations to build the final one because the .def file was created.


5) Create a String Table in a Resource File

- Create a new empty text file into the "TestDLL" folder (located in the Code::Blocks' Projects folder) and rename it as "TestDLL.rc" (this is a Resources file).
- Open the "....Projects\TestDLL\bin\Debug" folder.
- Use Notepad to open the file "libTestDLL.def" which contains the full list of our functions in their decorated form.

libTestDLL.def


- Go back to Code:Blocks
- In the "Projects" tab, Right Click on the project name ("TestDLL") and select "Add Files..."
- Select the file "TestDLL.rc" you just have created.
- When asked for "Multiple Selection", click on "Select All" then "OK" buttons : you just added the Resources file to the Project.
- Open the "Resources" tree then double click on the name "TestDLL.rc" to edit the file.
- Copy the code below in the Resource file. As you can see, this code contains the decorated form of the functions we previously found into the .def file.

Stringtable



6) Build the final version of the DLL (CTRL+F9)

7) Copy the file "TestDLL.dll" located into "....\Projects\TestDLL\bin\Debug" into the "plugins-user" folder of DBP (....Dark Basic Professional\Compiler\plugins-user).

8) Test our functions from DBP :

DBP Code



Of course you can create your DLL in release mode (Properties --> Build targets Tab)


I hope this will help.

Login to post a reply

Server time is: 2024-11-24 16:20:09
Your offset time is: 2024-11-24 16:20:09