C# dll

How can I include a C# DLL in XOJO? I tried the following, but did not work.

XOJO Code:

Declare Function AddTwo Lib "Test.dll" (a as Integer, b as Integer) As Integer
res = AddTwo(2,3)

Test.dll C# Code :

namespace Test
{
    public class Test_Class
    {
        public static int AddTwo(int a, int b)
        {
            return a + b;
        }
    }
}

BR
Sebastian

There are 2 kinds of code, managed (as C#, depends largely on its runtime) and unmanaged (as Rust, C, and C++). Xojo can only use and link to unmanaged code with “C like interfaces”. You could try to experiment C# unmanaged wrappers/exporters as said here:

Or write your DLL in Rust or C directly.

Hello @Sebastian_Fischer1,

For my AddTwo example, please follow the instructions at my website at: https://scispec.ca/index.php/blog/55-create-a-csharp-dll-for-xojo

There is example code that can be downloaded with my Github account at: GitHub - eugenedakin/CSharpDLLXojo: Build a DLL in CSharp with External Functions for Xojo

Please remember to download the Microsoft Build tools and Unmanaged Exports by Robert Giesecke to have the dll work in Xojo.

Warm regards. :slight_smile:

1 Like