Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
by Unlicensed Unknown user

Clarion has always had the capability of calling functions and procedures from non-Clarion DLLs. Documentation on the mechanics of how to do this is available within LanguageReference.pdf in the Clarion installation docs directory and does a fair job of explaining how to do things – as long as you are calling Windows API functions or functions in other non-.NET DLLs.

...

First, create a new class library:

Image RemovedImage Added

The default CPU is "any".

Image RemovedImage Added

Edit the CPU...

Image RemovedImage Added

and change it to x86:

...

Add Robert Giesecke's UNmanagedExports library using NuGet:

Image RemovedImage Added

You can also do this from the Package Manager console with

...

Write the source for the DLL, using the DllExport attribute:

Code Block
firstline
languagecsharp1
titleC#.NET Source Code
firstline1
linenumberstrue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;


namespace CMagLib
{
    public class CMagClass
    {
        [DllExport("Add2", CallingConvention = CallingConvention.StdCall)]
        public static int Add2(int arg1, int arg2)
        {
            return arg1 + arg2;
        }


        [DllExport("SubTxt2_3", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.BStr)]
        public static string SubTxt2_3([MarshalAs(UnmanagedType.BStr)] string arg1)
        {
            return arg1.Substring(1, 2);
        }


        [DllExport("RetText2", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.BStr)]
  public static string RetText2([MarshalAs(UnmanagedType.BStr)] string arg1, [MarshalAs(UnmanagedType.BStr)] string arg2)
        {
            return arg2;
        }
    }
}

...

Here's Brahn Patridge's Libmaker with the C# DLL loaded, before clicking Save as:

Image RemovedImage Added

Adding the lib to the project:

...