Extensions: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<tt>([a-zA-Z0-9\. _"\\']+)<\/tt>" to "{{hl|$1}}")
(Add Tabs to Minimum Viable Examples)
(One intermediate revision by the same user not shown)
Line 156: Line 156:
=== C# ===
=== C# ===


{{Feature|Informative|You might need to install [https://www.nuget.org/packages/UnmanagedExports UnmanagedExports]. You might also need to additionally set {{hl|WIN64}} and {{hl|WIN32}} in project properties. Go to: <tt>Project->Properties->Build tab->Conditional compilation symbols</tt>, add {{hl|WIN32}} for your {{hl|x86}} platform and  {{hl|WIN64}} for your {{hl|x64}} platform. Save. Rename resulting {{hl|WIN64}} {{hl|dllname.dll}} to {{hl|dllname_x64.dll}} }}
{{Feature|Informative|You might need to install [https://www.nuget.org/packages/UnmanagedExports UnmanagedExports]. You might also need to additionally set {{hl|WIN64}} and {{hl|WIN32}} in project properties. Go to: {{hl|Project->Properties->Build tab->Conditional compilation symbols}}, add {{hl|WIN32}} for your {{hl|x86}} platform and  {{hl|WIN64}} for your {{hl|x64}} platform. Save. Rename resulting {{hl|WIN64}} {{hl|dllname.dll}} to {{hl|dllname_x64.dll}} }}
<source lang="c#">
<source lang="c#">
/// <summary>
/// <summary>
Line 246: Line 246:
The following examples will copy the input into the output. They are provided to show some practical example.
The following examples will copy the input into the output. They are provided to show some practical example.


=== C ===
{{TabView
 
|title1= C (Visual C++)
==== Visual C++ ====
|content1=
{| class="wikitable"
<syntaxhighlight lang="c">
!|myextension.c
|-
| <source lang="c">
__declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
__declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
__declspec(dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
__declspec(dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
Line 288: Line 285:
strncpy_safe(output, "Test-Extension v1.0", outputSize);
strncpy_safe(output, "Test-Extension v1.0", outputSize);
}
}
</source>
</syntaxhighlight>
|}
 
==== GCC ====
|title2= C (GCC)
{| class="wikitable"
|content2=
!|myextension.c
<syntaxhighlight lang="c">
|-
| <source lang="c">
__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
Line 330: Line 325:
strncpy_safe(output, "Test-Extension v1.0", outputSize);
strncpy_safe(output, "Test-Extension v1.0", outputSize);
}
}
</source>
</syntaxhighlight>
|}
 
=== C++ ===


==== Visual C++ ====
|title3= C++ (Visual C++)
{| class="wikitable"
|content3=
!|myextension.cpp
<syntaxhighlight lang="cpp">
|-
| <source lang="c++">
#include <string>
#include <string>
#include <cstring>
#include <cstring>
Line 369: Line 359:
std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
}
}
</source>
</syntaxhighlight>
|}
 
==== GCC ====
|title4= C++ (GCC)
{| class="wikitable"
|content4=  
!|myextension.cpp
<syntaxhighlight lang="c++">
|-
| <source lang="c++">
#include <string>
#include <string>
#include <cstring>
#include <cstring>
Line 405: Line 393:
std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
}
}
</source>
</syntaxhighlight>
|}
 
=== C# ===
 
{| class="wikitable"
!|MyExtension.cs
|-
| <source lang="c#">


|title5= C#
|content5=
<syntaxhighlight lang="c#">
using System.Text;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
Line 458: Line 441:
}
}
}
}
</source>
</syntaxhighlight>
|}
 
=== C# (With callback) ===
{| class="wikitable"
!|MyExtension.cs
|-
| <source lang="c#">


|title6= C# (w/ callback)
|content6=
<syntaxhighlight lang="c#">
using System.Text;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
Line 523: Line 502:
}
}
}
}
</source>
</syntaxhighlight>
|}
}}




Line 533: Line 512:
If you know any of the following languages, consider editing this page to add the language to the upper list properly.
If you know any of the following languages, consider editing this page to add the language to the upper list properly.


=== Delphi/Pascal ===
{{TabView
 
|title1= Delphi/Pascal
{| class="wikitable"
|content1=  
!|&lt;unknown&gt;
<syntaxhighlight lang="delphi">
|-
| <source lang="delphi">
library dllTest;
library dllTest;


Line 557: Line 534:
begin
begin
end.
end.
</source>
</syntaxhighlight>
|}


=== D ===
|title2= D
 
|content2=  
{| class="wikitable"
<syntaxhighlight lang="d">
!|&lt;unknown&gt;
|-
| <source lang="d">
import std.c.windows.windows;
import std.c.windows.windows;
import core.sys.windows.dll;
import core.sys.windows.dll;
Line 608: Line 581:
doutput[result.length] = '\0';
doutput[result.length] = '\0';
}
}
</source>
</syntaxhighlight>
|}
}}




Line 623: Line 596:
* [http://killzonekid.com/arma-scripting-tutorials-how-to-make-arma-extension-part-3/ ArmA Scripting Tutorials: How To Make ArmA Extension (Part 3)]
* [http://killzonekid.com/arma-scripting-tutorials-how-to-make-arma-extension-part-3/ ArmA Scripting Tutorials: How To Make ArmA Extension (Part 3)]
* [http://killzonekid.com/arma-scripting-tutorials-how-to-make-arma-extension-part-4/ ArmA Scripting Tutorials: How To Make ArmA Extension (Part 4)]
* [http://killzonekid.com/arma-scripting-tutorials-how-to-make-arma-extension-part-4/ ArmA Scripting Tutorials: How To Make ArmA Extension (Part 4)]
==== C# ====
==== C# ====
* [http://maca134.co.uk/tutorial/write-an-arma-extension-in-c-sharp-dot-net/ Write An ARMA Extension In C#/.NET]
* [http://maca134.co.uk/tutorial/write-an-arma-extension-in-c-sharp-dot-net/ Write An ARMA Extension In C#/.NET]
==== Golang ====
==== Golang ====
* [https://github.com/code34/armago_x64/ Armago An Arma Template Extension In Golang]
* [https://github.com/code34/armago_x64/ Armago An Arma Template Extension In Golang]

Revision as of 15:38, 16 November 2021

If you came here because you have been told to install an extension, be warned! Extensions are just like executables. They may contain viruses etc. More on that, in the FAQ section.


Historical

  • Logo A2.png1.61 The first stable version of this functionality arrived.
  • Arma 3 logo black.png1.18 Linux (server) support was introduced.
  • Arma 3 logo black.png1.68 The ability to pass multiple arguments to callExtension and the interface RVExtensionArgs got added.
  • Arma 3 logo black.png1.70 RVExtensionVersion became available. It is called when the extension loads. Will be printed into the RPT log.


FAQ

How to use Extensions?

Extensions can be accessed using callExtension.

The exact way about how to use an extension is up to the developer of said extension

Where to put Extensions?

Arma 3 will look at the following places to find your extension files:

  • In all loaded mods root folders (for example: ..\arma3\@ModXYZ\yourextension.dll).
  • In your Arma 3 installation folder (for example: ..\arma3\yourextension.dll).

At best, you place your extensions inside some mod folder and load it. At worst, you just throw it where the Arma 3 executable is located.

Extensions may require other libraries and runtimes to be installed on the computer it is to run on. Consult the authors installation manual if it exists.

What are Extensions?

Extensions are Dynamic Link Library (DLL) files written in, for example, C.

Linux systems use a different file type: Shared Object (SO).

What do I have to look out for?

Extensions fall under the same rules as executable files. They may require additional runtime libraries or cause the game to crash.

Extensions can contain malicious code!


How to know which extensions can be trusted?

Theoretically, never trust anything! Including Arma and your OS itself. Technically however, this would make a boring experience, as all you would be left with is an expensive heater.

Thus a better rule is: If the are sources freely available, you probably can trust the extension. Even if you cannot read the source code, chances are that somebody out there can and would find something odd. That will not protect you! Developers might add malicious code that is not exposed in the available source files, they not even need to be aware of this. They may be infected already and the virus is just writing itself into the compiled extension.

When I call the extension method, Arma freezes.

This is most likely caused by the extension taking too much time. Due to the low-level nature of extensions, an extension cannot be suspended like scheduled scripts can be. You should notify the developer of said extension about this freezing issue or use the extension less extensively.

Can I join BattlEye protected servers with my extension?

If the extension is whitelisted by BattlEye, it will be allowed to load. If it is not, it just will be blocked causing any callExtension attempt to fail.

Generally speaking, joining BattlEye protected servers should be no problem with or without extensions.

If in doubt, ask the extensions author.

Can I use extensions in my mission?

Yes, you can use extensions in your missions, but you should consider if it is worth it. Using extensions requires that all hosts (servers and clients) which use the extension have it installed. Extensions are not packed into the mission pbo.

If only the server is using the extension, the clients do not need it.

What do i have to look out for when deploying my extension?

Extensions have to be provided for 32bit and 64bit Arma. When you deploy your extension, you thus have to build it twice. Once for the 32bit support and once for the 64bit support.

After you are done, copy both output files to some location and add a _x64.dll suffix to the 64bit file.

Example:

  • MyExtension.dll (32bit)
  • MyExtension_x64.dll (64bit)


Creating Extensions

Preamble

Before we start, ask yourself the following questions:

  • is SQF unable to fulfill your needs?
  • Making an extension requires knowledge of a programming language. Are you capable of performing that programming task?
  • Why should a user trust you and use your extension?
  • Is it worth adding an extension for the feature you want to implement?

If the answer to any question was no, you probably should not proceed to create an extension but rather use plain SQF.


Getting Started

At first, we have to choose what language we want to use.

This wiki currently covers the following: C, C++, C#

Preparations

C/C++

Create a new library project in the IDE of your choice.

C#

C# requires you to install additional dependencies to work out of the box. The snippets in here all are using DllExport (sources) which can be installed using NuGet.

Create a new Class Library project in the IDE of your choice.


Available Interfaces

The Extension is required to contain at least the entry point in a form of a method named RVExtension or RVExtensionArgs. Everything else is optional.

The actual exports need to look like this (Windows only):

32-bit requires usage of decorated names following the __stdcall convention

  • _RVExtension@12
  • _RVExtensionArgs@20
  • _RVExtensionVersion@8

64-bit

  • RVExtension
  • RVExtensionArgs
  • RVExtensionVersion

If you use the Visual C++ compiler, this should work out of the box. But other compilers might require some manual work.

C/C++

Visual C++

	//--- Called by Engine on extension load 
	__declspec (dllexport) void __stdcall RVExtensionVersion(char *output, int outputSize);
	//--- STRING callExtension STRING
	__declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
	//--- STRING callExtension ARRAY
	__declspec (dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);

GCC

	//--- Called by Engine on extension load 
	__attribute__((dllexport)) void RVExtensionVersion(char *output, int outputSize);
	//--- STRING callExtension STRING
	__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
	//--- STRING callExtension ARRAY
	__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);

See GCC documentation on "How to use the new C++ visibility support"

C#

You might need to install UnmanagedExports. You might also need to additionally set WIN64 and WIN32 in project properties. Go to: Project->Properties->Build tab->Conditional compilation symbols, add WIN32 for your x86 platform and WIN64 for your x64 platform. Save. Rename resulting WIN64 dllname.dll to dllname_x64.dll
		/// <summary>
		/// Gets called when arma starts up and loads all extension.
		/// It's perfect to load in static objects in a seperate thread so that the extension doesn't needs any seperate initalization
		/// </summary>
		/// <param name="output">The string builder object that contains the result of the function</param>
		/// <param name="outputSize">The maximum size of bytes that can be returned</param>
#if WIN64
		[DllExport("RVExtensionVersion", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionVersion@8", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtensionVersion(StringBuilder output, int outputSize) { }

		/// <summary>
		/// The entry point for the default callExtension command.
		/// </summary>
		/// <param name="output">The string builder object that contains the result of the function</param>
		/// <param name="outputSize">The maximum size of bytes that can be returned</param>
		/// <param name="function">The string argument that is used along with callExtension</param>
#if WIN64
		[DllExport("RVExtension", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtension@12", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtension(StringBuilder output, int outputSize,
		   [MarshalAs(UnmanagedType.LPStr)] string function) { }

		/// <summary>
		/// The entry point for the callExtensionArgs command.
		/// </summary>
		/// <param name="output">The string builder object that contains the result of the function</param>
		/// <param name="outputSize">The maximum size of bytes that can be returned</param>
		/// <param name="function">The string argument that is used along with callExtension</param>
		/// <param name="args">The args passed to callExtension as a string array</param>
		/// <param name="argsCount">The size of the string array args</param>
		/// <returns>The result code</returns>
#if WIN64
		[DllExport("RVExtensionArgs", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionArgs@20", CallingConvention = CallingConvention.Winapi)]
#endif
		public static int RvExtensionArgs(StringBuilder output, int outputSize,
			[MarshalAs(UnmanagedType.LPStr)] string function,
			[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] args, int argCount) { }


Getting your extension whitelisted by BattlEye

SinceArma 3 logo black.png1.46, client extensions need to be whitelisted in order to get loaded.

The SitRep #00109 said the following on that topic:

 The enhanced BattlEye protection in 1.46 will require extensions to be white-listed, or their access to the game's processes will be blocked.
 In order to get your extension white-listed, please contact BattlEye support via its web form or support[at]battleye.com.
 Be sure to include the file name, a description and possibly a download link.

This boils down to the following tasks to get your extension whitelisted:

  1. Upload the extension in question somewhere.
  2. Open the BattlEye Contact Page.
  3. Pick the topic Other requests (may change in future, select most appropriate).
  4. Fill in your Name and E-Mail.
  5. Set the subject to something like Arma extension whitelisting.
  6. Add link to your extension from step 1 (you may include other information too) into the Message.

After a certain time, your extension should be whitelisted.


Deploying extensions

To correctly deploy your extensions, you have to make sure to have a 32bit and a 64bit variant of your extension. The reason for this is because 64bit Arma cannot load 32bit extensions and vice versa.

You also should create an addon package (even if you only deploy the actual extension binaries) + add the documentation for your extension.

An example might be structured like this:

  • /@MyExtension/
    • /MyExtension.dll
    • /MyExtension_x64.dll
    • /docs/
      • /MyExtension_Documentation.txt

You may also want to provide convenience SQF functions to access your extension.


Minimum Viable Example

The following examples will copy the input into the output. They are provided to show some practical example.

C (Visual C++)
C (GCC)
C++ (Visual C++)
C++ (GCC)
C#
C# (w/ callback)
__declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
__declspec(dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
__declspec(dllexport) void __stdcall RVExtensionVersion(char *output, int outputSize);

int strncpy_safe(char *output, const char *src, int size)
{
	int i;
	size--;
	for (i = 0; i < size && src[i] != '\0'; i++)
	{
		output[i] = src[i];
	}
	output[i] = '\0';
	return i;
}

void __stdcall RVExtension(char *output, int outputSize, const char *function)
{
	strncpy_safe(output, function, outputSize);
}

int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc)
{
	int index = 0;
	for (int i = 0; i < argc && index < outputSize; i++)
	{
		index += strncpy_safe(output + index, argv[i], outputSize - 1 - index);
	}
	return 0;
}

void __stdcall RVExtensionVersion(char *output, int outputSize)
{
	strncpy_safe(output, "Test-Extension v1.0", outputSize);
}
__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
__attribute__((dllexport)) void RVExtensionVersion(char *output, int outputSize);

int strncpy_safe(char *output, const char *src, int size)
{
	int i;
	size--;
	for (i = 0; i < size && src[i] != '\0'; i++)
	{
		output[i] = src[i];
	}
	output[i] = '\0';
	return i;
}

void RVExtension(char *output, int outputSize, const char *function)
{
	strncpy_safe(output, function, outputSize);
}

int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc)
{
	int index = 0;
	for (int i = 0; i < argc && index < outputSize; i++)
	{
		index += strncpy_safe(output + index, argv[i], outputSize - 1 - index);
	}
	return 0;
}

void RVExtensionVersion(char *output, int outputSize)
{
	strncpy_safe(output, "Test-Extension v1.0", outputSize);
}
#include <string>
#include <cstring>
#include <sstream>
extern "C"
{
	__declspec(dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
	__declspec(dllexport) int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
	__declspec(dllexport) void __stdcall RVExtensionVersion(char *output, int outputSize);
}
void __stdcall RVExtension(char *output, int outputSize, const char *function)
{
	std::strncpy(output, function, outputSize - 1);
}

int __stdcall RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc)
{
	std::stringstream sstream;
	for (int i = 0; i < argc; i++)
	{
		sstream << argv[i];
	}
	std::strncpy(output, sstream.str().c_str(), outputSize - 1);
	return 0;
}

void __stdcall RVExtensionVersion(char *output, int outputSize)
{
	std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
}
#include <string>
#include <cstring>
#include <sstream>
extern "C"
{
	__attribute__((dllexport)) void RVExtension(char *output, int outputSize, const char *function);
	__attribute__((dllexport)) int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc);
	__attribute__((dllexport)) void RVExtensionVersion(char *output, int outputSize);
}
void RVExtension(char *output, int outputSize, const char *function)
{
	std::strncpy(output, function, outputSize - 1);
}

int RVExtensionArgs(char *output, int outputSize, const char *function, const char **argv, int argc)
{
	std::stringstream sstream;
	for (int i = 0; i < argc; i++)
	{
		sstream << argv[i];
	}
	std::strncpy(output, sstream.str().c_str(), outputSize - 1);
	return 0;
}

void RVExtensionVersion(char *output, int outputSize)
{
	std::strncpy(output, "Test-Extension v1.0", outputSize - 1);
}
using System.Text;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

class MyExtension {

#if WIN64
		[DllExport("RVExtensionVersion", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionVersion@8", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtensionVersion(StringBuilder output, int outputSize)
		{
			output.Append("Test-Extension v1.0");
		}

#if WIN64
		[DllExport("RVExtension", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtension@12", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtension(StringBuilder output, int outputSize,
			[MarshalAs(UnmanagedType.LPStr)] string function)
		{
			output.Append(function);
		}

#if WIN64
		[DllExport("RVExtensionArgs", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionArgs@20", CallingConvention = CallingConvention.Winapi)]
#endif
		public static int RvExtensionArgs(StringBuilder output, int outputSize,
			[MarshalAs(UnmanagedType.LPStr)] string function,
			[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] args, int argCount)
		{
			foreach(var arg in args)
			{
				output.Append(arg);
			}
			return 0;
		}
}
using System.Text;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

class MyExtension {

	public static ExtensionCallback callback;
	public delegate int ExtensionCallback([MarshalAs(UnmanagedType.LPStr)] string name, [MarshalAs(UnmanagedType.LPStr)] string function, [MarshalAs(UnmanagedType.LPStr)] string data);

#if WIN64
		[DllExport("RVExtensionRegisterCallback", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionRegisterCallback@4", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RVExtensionRegisterCallback([MarshalAs(UnmanagedType.FunctionPtr)] ExtensionCallback func)
		{
			callback = func;
		}

#if WIN64
		[DllExport("RVExtensionVersion", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionVersion@8", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtensionVersion(StringBuilder output, int outputSize)
		{
			output.Append("Test-Extension v1.0");
		}

#if WIN64
		[DllExport("RVExtension", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtension@12", CallingConvention = CallingConvention.Winapi)]
#endif
		public static void RvExtension(StringBuilder output, int outputSize,
			[MarshalAs(UnmanagedType.LPStr)] string function)
		{
			output.Append(function);
		}

#if WIN64
		[DllExport("RVExtensionArgs", CallingConvention = CallingConvention.Winapi)]
#else
		[DllExport("_RVExtensionArgs@20", CallingConvention = CallingConvention.Winapi)]
#endif
		public static int RvExtensionArgs(StringBuilder output, int outputSize,
			[MarshalAs(UnmanagedType.LPStr)] string function,
			[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 4)] string[] args, int argCount)
		{
			foreach(var arg in args)
			{
				output.Append(arg);
			}
			return 0;
		}
}


Other Languages

This section contains other languages which may or may not work. Finding out requirements etc. is up to you.

Help Wanted!

If you know any of the following languages, consider editing this page to add the language to the upper list properly.

Delphi/Pascal
D
library dllTest;

uses
  SysUtils;

{Return value is not used.}
procedure RVExtension(toArma: PAnsiChar; outputSize: Integer; fromArma: PAnsiChar); stdcall; export;
begin
  StrCopy(toArma, fromArmA);
end;

exports
  { 32-bit }
  RVExtension name '_RVExtension@12';
  { 64-bit }
  RVExtension name 'RVExtension';
begin
end.
import std.c.windows.windows;
import core.sys.windows.dll;

__gshared HINSTANCE g_hInst;

extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) {
	final switch (ulReason) { 
		case DLL_PROCESS_ATTACH:
			g_hInst = hInstance;
			dll_process_attach(hInstance, true);
			break;

		case DLL_PROCESS_DETACH:
			dll_process_detach(hInstance, true);
			break;

		case DLL_THREAD_ATTACH:
			dll_thread_attach(true, true);
			break;

		case DLL_THREAD_DETACH:
			dll_thread_detach(true, true);
			break;
	}

	return true;
}

import std.conv;
import std.exception;

export extern (Windows) void RVExtension(char* output, int output_size, const char* cinput) {
	auto dinput = to!string(cinput);
	auto doutput = output[0 .. output_size];
	string result;

	// ...

	enforce(result.length <= output_size, "Output length too long");
	doutput[0 .. result.length] = result[];
	doutput[result.length] = '\0';
}


External References

The Community-Lead Examples Repository can be used for further examples which go more into detail. To get your example on there, just fork the repository and create a Pull-Request afterwards.

C/C++

C#

Golang

External applications