How To: Use DllImport from C# to call a clarion procedure

Just for fun, can we call into ClaRun directly from C#?

Why yes, we can! :slight_smile:

using System;
using System.Runtime.InteropServices;

namespace ClarionDllImport
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Testing ClarionDllImport");
            Console.WriteLine(MyClaToday());
            Console.ReadKey();
        }

        [DllImport("ClaRun.dll", EntryPoint = "Cla$TODAY")]
        public static extern int MyClaToday();
    }
}

Result:

1 Like

Is this still possible?
I got an error when performing this procedure.

Sounds like you have “a bug”. Fix that bug and it will work.

If that does not work maybe tell us the Error Message (screen shot is nice), and show your code and project settings.

I was able to use claRun like the example.
We have to run the program in 32Bits
In my case, I need to do a little more work to understand the process of using my Clarion procedures in C#.

Thanks for the feedback.

Can you give us the Error Message you were getting so we can more easily spot the 32-bit problem? Also a screen shot of the project setting in VS you changed?

DLL Clarion
image