Some help with C# interop

I received this message through the contact form at ClarionAddins the other day. Unfortunatly the lovely helpful person didn’t leave any contact detail. In case it is helpful to anyone I thought I might share it here.

Please do get in touch if this was you!

In a recent project I used the Unmanaged Exports nuget package to make a c# dll compatible with Clarion. The project I was working on was a multi-dll project with 8 or 9 Clarion dlls and I was adding the C# dll to this environment. I don’t know the specifics of why this happened but it was throwing error when trying to call a function on the C# dll from a Clarion dll, 0xc000005 Access Violation Error. To fix this you had to use the Windows API LoadLibrary function in the beginning of the program and/or call a c# function in the executable of the project prior to the dlls calling any of the c# functions.

Hope this helps incase anyone runs into the same issue I did.

When I do interop with using the unmanaged exports technique I use the LoadLib class on the clarion side. I am not sure where to get this anymore, perhaps @julesVerne can help with that?

In case you are curious here is an answer I put on StackOverflow about Clarion callbacks and Unmanaged Export interop:

Brahn, the Load Lib class is from Larry Sand.
I’m not sure if he has a download link for it, but I’m sure we can check with him.

Thanks @Rick_UpperPark. I seem to remember getting it from ClarionMag but I cannot locate it anymore. Hopefully Larry (a.k.a. @julesVerne) will join us here to help out :smile:

The code is available from Clarion Magazine:

1 Like

Hi i know this is an old post but im stuck with this same problem.

¿How do i use libmaker to make friendly clarion lib from an Unmanaged Export from a C# DLL?

¿Is there any link still available to help me with this issue?



@Martin_Vecchione you will need a customized version of LibMaker. The one that ships with the Clarion examples has some bugs in it. @MarkGoldberg has one that should do the job hosted on GitHub:

Hi @brahn no luck it seems that @MarkGoldberg version of LibMaker doesn`t export the libs file i need. I try to use the sample code you post in StackOverlfow without luck.

Actually im using the code posted in ClarionMag but i dont know why i`m getting 0xc000005 Access Violation Error when i use it in a Multi-dll project…try to LoadLibrary in the main exe begore calling c# function but i still get the same error.

Any clues?


Isn’t that article about COM Interop? I don’t have a subscription at the moment but from memory I think it is. In that case LibMaker won’t help you. It only works if you are using UnmanagedExports from .NET and correctly decorating your methods with the DllExport property.

Yeap its about COM interop, actually COM works pretty well but we have the problem to register before using it (its a pain when user dont administrative account)…so im trying to move to native c++ wrapper.

When i try to use the code you posted in StackOverflow a few yearks ago i came with the problem that i dont have a customized libmaker to make friendly Clarion lib files so i create a managed visual c++ as a wrapper and then call it from a clarion dll and i get 0xc000005 Access Violation Error.

Thats where im stuck right now and dont know how to move foward


The think is, LibMaker won’t help you with the COM interop. If you are trying to use LibMaker for your c++ wrapper then the shipping LibMaker should work fine or certainly the one from Mark will work too.

The later versions of Clarion, C9.1 and up I think, support RegFree COM but I have never used it myself. You might want to investigate that or maybe @davbrat can help out?

I recently had to add functionality from a C# dll to clarion project. Thanks to the great help from @MarkGoldberg on Skype I was able to get this done.

First of all you will need to download and compile the modified libmaker from
Open the .cwproj or for C6 and older, open the .prj and compile

After testing with normal datatypes like long and float I was able to confirm that my LIB was correct. Now for the string part it is important to remember that Clarion will use CString meaning you will have to marshalAs your string parameters

   [DllExport("doEnrollFPUser", CallingConvention = CallingConvention.StdCall)]
   public static void doEnrollFPUser([MarshalAs(UnmanagedType.LPStr)]string p_parameters)
        { ......

After this you build your LIB and add to your clarion app. Add the procedure you are going to call with the prototype correctly setup as

(*CString passedString),NAME('doEnrollFPUser'),PASCAL,RAW,DLL(TRUE)

To use the new procedure in your clarion app you will have to set a new CString variable and pass that new variable to your procedure

Hope this makes sense and could be of help to any one out there


I tried 3 different libmakers. MGLibMaker is the only libmaker which produces correct lib from .net assemblies.

But there is a system dll that no one libmaker can handle:
Dwmapi.dll (it can be found in windows\system32 folder). All 3 show no entries, as if the dll has no exported functions. But it definitely has, all exported functions are accessible by LoadLibrary/GetProcAddress, and for example Total Commander’s dll viewer shows all exports correctly.

I’m seeing entries with the vanilla C11 libmaker. But not ALL of the entries. There are a bunch of dwmapi.## exports that I can see in PE Explorer. Here’s what I see in Libmaker.

Here’s part of PE Explorer:

Jim Kane’s LoadLib class supports loading procedures by the ordinal number. But it helps to know what the ordinal represents.

I used his class to write my QuickCrypt wrapper, but I had docs for the DLL.

1 Like

Aha, now I see all exports as well. My fault was that I selected the dll not from windows\system32, but from my own location where I copied the dll to. Although, Total Commander shows all exports even from my location.

GetProcAddress supports ordinal number as a passed value instead of function name.

1 Like