How to Compile a DLL
By Vindicated
Hello there. This is a guide on how to compile a DLL. Have you have seen a C++ script that you don't know how to add to your server? Well this is your solution. After this guide you will be able to compile C++ scripts for your server. This guide is mostly text-based, so good English skills are probably nice. I would recommend using the video in addition to this text guide. It may clear up some questions you have on some things... and you get to hear my sexy voice!
You will see many shorter and simpiler guides on compiling a DLL. There are many methods to compile a DLL, but I will show you the "true way" or the project way. Using this method will allow your C++ script to have its own DLL (like TeleportNPC.dll), without having to put it in with other scripts. You must also know how to compile ArcEmu prior to starting this guide. In this guide I will use my custom TeleportNPC as a guideline, so just modify it for the script you're using.
[ame="http://www.youtube.com/watch?v=ZKggcSlwZOo"]YouTube - How to Compile a DLL (ArcEmu)[/ame]
Suggestion: Watch the video on Youtube. Don't try and watch it here (Better quality + bigger)
Download Prerisques:
Microsoft Visual C++: Visual C++ 2008 Express Edition
Sample Project: http://www.filefactory.com/file/af31gch/n/Sample_Project_rar
I. Getting the Source
The first step in compiling your custom DLL is to find the file that you wish to compile. There are many scripts out there on MMOwned to use, but we will be compiling my custom TeleportNPC (Please keep in mind it wasn't made for its features :P). This is included in my sample project download at the top.
Normally, however, you are not presented with a download to the source code, you just get the script in code tags. When this occurs, copy/paste the script into Notepad and go File > Save As. Name the file "ScriptName.cpp" and for the "Save as type:" field select "All Files". You have just saved the cpp file. Move it into the project folder and follow the rest of my guide.
II. Setting up Setup Files
Now that you have the source code for the script, it's time to setup our source files, or "Setup.cpp" and "Setup.h". First, lets open up the source of our main script (TeleportNPC.cpp in this case) and look for the line:
Code:class SCRIPT_DECL TeleportNPC : public GossipScript
Lets remember the name after SCRIPT_DECL, we will need it later (this varies for every script).
Second, lets open up Setup.cpp. Go to the line that says:
Code:extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr) { SetupScriptName(mgr); }
Edit the part after the word setup to what you found after SCRIPT_DECL in the main file. In this case it is "SetupTeleportNPC(mgr);". Save and exit out.
Now open up the file "Setup.h". Find the line:
Code:void SetupScriptName(ScriptMgr * mgr);
Edit the part after the word setup to what you found after SCRIPT_DECL in the main file. In this case it is "void SetupTeleportNPC(ScriptMgr * mgr);". Save and exit out.
You have just successfully edited your setup files.
III. Creating the Project File
We are almost there! Now right click the file "ScriptName" with a picture that looks like a program with two plus signs on it and choose to open it with Notepad. Use the keyboard shortcut CTRL H. In the "Find what" field enter in "ScriptName" (Do not fill it in with your script name). In the "Replace with" field enter in your script name, in this case that is "TeleportNPC" (without quotes). Save the file and exit out.
You are now ready to compile your DLL.
IV. Compiling the DLL
Move the project file out of the "SampleProject" folder. Rename the folder your project name, in this case will will rename it "TeleportNPC". Now, move the TeleportNPC folder to "trunk\src\scripts\src" and move the project file to "trunk\src\scripts\projects" Double click on the TeleportNPC project.
Click the plus symbol right next to your project name and right click Main Resources then click Add > Exsisting Item. Select Setup.cpp & Setup.h. Now right click Scripts and click Add > Exsisting Item and select your main source file (TeleportNPC.cpp).
Double click your project file and at the top you should see some dropdown menus, one of them should be labled "Debug". Click the down arrow and select "Release". Now use the keyboard shortcut F7. You script is compiled (Go to arcemu\trunk\bin\Release\script_bin).
You will only have to repeat step 4 (the second paragraph) when compiling the DLL after this time. You will need to recompile your DLL everytime you make a change to it. You will also need to recompile it every time you update your ArcEmu revision.
If you have any questions, problems, or requests just reply to this post.
Thanks,
Vindicated