Setting Visual Studio Up for Making Binary Modules

From Garry's Mod
Jump to: navigation, search

Contents

Basic Understanding of C++

Before you continue you should already have a basic understanding of C++. I recommend reading up tutorials found here.

Downloading your IDE

First of all you want to download Visual Studio 2010. It's all personal preference what IDE you use. You can use 2012 or a 2013; you don't even have to use Visual Studio. Visual Studio 2010 is what I'm using for this tutorial, so I recommend using it if it's your first module.

Garry's Mod Lua Headers

The headers you need and an example are available here. You'll need to click "Download Zip" found to the right of the page. From there extract the include folder somewhere, I recommend somewhere like "C:\Garry's Mod Lua Headers" or "C:\Users\<username>\Documents\Garry's Mod Lua Headers"

Creating a New Project

Open your IDE, in this case Visual Studio 2010, then select new project.

Select "Win32" then click "OK". From here select Win32 Project make the name whatever you want. I recommend something like gm_test for your first module.


New Project Info.png


There should be a Win32 Application Wizard opened, click next then under "Application type" select DLL. Then check the box "Empty project", finally click "Finish".


Win32 Application Wizard.png

Congratulations! You now have an empty project.

Setting Up the Project

Now that you have your empty project you need to set up some directories, add some files and set some properties. Firstly you need to right click the folder "Source Files" and then click "Add new item...".


Add new item.png


From inside here click "C++ file (.cpp)", name it "main".


Add new main.png


The the next thing you must do is set it to release mode. At the top, near the green play looking button, you should see "Debug" then "Win32". Open the drop down menu on "Debug" and set it to "Release".


Set to release.png


Properties

Now right click your project, in this case "gm_test", and then click "Properties".


Visual Studios properties.png


Configuration Properties

Go into "Configuration Properties" and under "Project Defaults" then go to "Character Set" and select "Use Multi-Byte Character Set". This is helpful with strings so you don't have to use useless shit. Next in "Configuration Properties" make the "Target Name" something like "gmcl_test_win32" so that you can just drag and drop it into your lua/bin folder without having to rename it after every compile.


Visual Studios configuration properties.png


C/C++

Now that that's out of the way, click the "C/C++" category and then select "Additional Include Directories", in the drop down menu, select "<Edit...>".


Visual Studios ccplusplus properties.png


From inside this menu select the little folder icon this should make a new blank entry. Double click it then select the "..." button.


Visual Studios aditional include directories.png


Now go to where you saved your headers to, in this case "C:\Garry's Mod Headers\" from here go to "include\GarrysMod\Lua" then click "Select folder". Your full path should be something along the lines of "C:\Garry's Mod Headers\include\GarrysMod\Lua".


Visual Studios aditional folder select.png


Click OK, then Click Apply, then Click OK again. You're almost ready to compile your first module.

Main.cpp

Open up main.cpp and add the following code:

#define GMMODULE

#include "Interface.h"

// Called when the module opens
GMOD_MODULE_OPEN()
{
    return 0;
}
// Called when the module closes
GMOD_MODULE_CLOSE()
{
    return 0;
}

Compiling

If done correctly, you should be able to compile it. Right click your project and click "Rebuild", note that it's a good habit to always select rebuild instead of build.

Visual Studios rebuild.png

Personal tools
Navigation