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:
The default CPU is "any".
Edit the CPU...
and change it to x86:
...
Add Robert Giesecke's UNmanagedExports library using NuGet:
You can also do this from the Package Manager console with
...
Write the source for the DLL, using the DllExport attribute:
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
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:
Adding the lib to the project:
...