Write An ARMA Extension In C#/.NET

Hey, so like me you want the ability to do more with ARMA but C++ is not one of your favorite languages, here is a small tutorial on how to write a working ARMA DLL completely in C# (and other .NET languages I presume), no need for C++/CLR or ARMA2NET.

First, if you have not got it already, download Visual Studio Community 2013 from here: https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

Once installed, start a new C# “Class Library” project.
Screenshot at 00-57-38Next step is to download a NuGet Package called “Unmanaged Exports“. To do this goto the menu “Project -> Manage NuGet Packages”, once the dialog opens, search for “Unmanaged Exports”, install it and close the dialog.
Screenshot at 01-02-21Now, the project is setup and you are ready to writing some code. Here is the most basic of examples (Download link below).Screenshot at 01-12-06

The class itself can be called anything, DllEntry seems appropriate. Once you compile the code, the RVExtension gets called whenever you execute a callExtension. In the SQF code below, the function string, is available via the function param in RVExtension. (I had a string encoding issue, i thought maybe marshaling would help…not sure…).

_output = "dllname" callExtension "function"; // _output == "noitcnuf"

Before you can compile, the Unmanaged Exports requires the projects “Platform Target” to be set to either x86 or x64 (I suggest x86 if you are not sure). To do this right click on the project and select “Properties”, click the “Build” section and change the “Platform Target” dropdown.
Screenshot at 01-25-09

Now compile the project and put the resulting DLL into an ARMA mod folder. (Eg. @armaExtCS). Thats it, to run it in ARMA just execute this:

_output = "ARMAExtCS" callExtension "function";

Screenshot at 01-28-24Screenshot at 01-29-37

View the source and download

Be Sociable, Share!

9 thoughts on “Write An ARMA Extension In C#/.NET”

        1. To ensure the output text doesn’t overflow and cause a crash. Its more of a “just in case” kinda thing

  1. Hello,

    I’m german so my english is very bad.

    I’m making scripts for Arma 3 in sqf, so I have a folder with a mission.sqm file. In the same folder, I had to copy the .dll file from the .cs project. So I have actually a mission.sqm file and my ARMAExtCS.dll file.

    Now I started Arma 3 -> Editor -> load my mission and wrote the same code in my debug console, but it didn’t work.

    Maybe you understood what I tried to write and maybe you can help me.

    Dr. Prof. Evil aka Tom

    1. Once you have compiled the dll, to call it, you need to place is in ARMA root folder (not great) or in a @mod folder.
      Then do:

      "ARMAExtCS" callExtension "test";

Leave a Reply

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