Calling X-Plat C# library in Xojo

Thanks so much, @eugenedakin!

Are you using the “dllExport” package?
Were you unable to make the Windows example work even? That seems to work fine for me.

I’m trying to see if dllExport package will work under MacOS. The author doesn’t check e-mails it seems, and it’s not specified on his site.

Just out of curiousity, does your C++ dll work on MacOS?

I tried, and couldn’t seem to find instructions that ran. I always ended up with errors and the dll could not be created. This was all on Windows 10.

I haven’t tried it on a Mac, as mine is VERY old :slight_smile: Its a late 2009 3.1 model 220px-Mac_Mini_(early_2009)_7786

What OS version?

Ok, that’s strange! What errors specifically?

I didn’t have much trouble, using the examples here
or here.

I’m away for the weekend, but next week I’ll link my Xojo and C# project.
I was using Xojo 2019r1.1 and VS2019.

Lol, Snow Leopard.

This might interest you.
I have Catalina running on my old 2009 MBP…

Its all good, there is no rush. Here are the errors that I have along with the instructions on trying to get it running:

  1. Start Visual Studio 2019 in administrator mode
  2. Create a new project button
  3. Create a ‘Class Library (.NET Framework) ->Next
  4. Save file as ‘XojoCL’
  5. Go to the toolbar: Tools->NuGet package manager->Package Manager Console
    a. A Package manager console tab is opened at the bottom of the Visual Studio IDE with ‘PM>’
    PM> ‘Install-Package UnmanagedExports -Version 1.2.7
  6. Press enter to install this package.
  7. Select Build->Configuration Manager
    a. Active solution configuration->Release
    b. Active solution platform->New->x64
  8. Tools->NuGet Project Manager->Manage NuGet Packages for Solution
  9. Search for DllExport
  10. install
  11. Select x64 , check for proper solution (sln) path, press apply
  12. Select XojoCL project
  13. Restart Visual Studio and reload the XojoCL project.
  14. Add the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;

public class TestExport
{
[DllExport]
public static int AddTwo(int a, int b)
{
return a + b;
}
}

Here are the errors:
1>------ Rebuild All started: Project: XojoCL, Configuration: Release x64 ------
1> XojoCL -> C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\XojoCL\bin\x64\Release\XojoCL.dll
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: The “DllExportAppDomainIsolatedTask” task failed unexpectedly.
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: System.ArgumentException: Requested value ‘Version47’ was not found.
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018:
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: Server stack trace:
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.<>c__DisplayClass8.<GetGetToolPathInternal>b__7(Version version, String toolName) in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 568 1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.TryToGetToolDirForFxVersion(String toolFileName, Func3 getToolPath, String& toolDirectory) in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 725 1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.ValidateToolPath(String toolFileName, String currentValue, Func3 getToolPath, String& foundPath) in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 698 1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.ValidateFrameworkPath() in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 680
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.ValidateInputValues() in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 396 1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.ExportTaskImplementation1.Execute() in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 264
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask.Execute() in c:\Users\rober_000\Documents\Code\unmanaged-exports\RGiesecke.DllExport.MSBuild\DllExportAppDomainIsolatedTask.cs:line 241
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object args, Object server, Object& outArgs)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018:
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: Exception rethrown at [0]:
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at Microsoft.Build.Framework.ITask.Execute()
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Users\eugen\Desktop\New\NetFromXojo\XojoCL\packages\UnmanagedExports.1.2.7\tools\RGiesecke.DllExport.targets(58,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

1 Like

Of course, after all the hoops I tried jumping through to get to work x-plat, I no longer can get the Windows one to work anymore.
BUT, it looks like this functionality will be coming to a .NET near you…


Scroll down about half way to the section called “Native Exports”. Seems like they have some work to do, but this certainly looks promising, especially since they specifically state it’ll be x-plat.

I’m going to play with the code they linked to and see if I can get something working.
It’s unfortunate that Xojo gives no more details to what the exact problem is other than “function not found” if the format of the dll is not to it’s liking…

Thanks for your help with this, @eugenedakin and @npalardy!

1 Like

Nice list of features !

These two look fun !

Support Single-File Apps in .NET 5
.NET 5.0 also includes support for Web Assembly

At the end of 2021 there’s a lot of good promises with NET6. THAT will light up my interest in .Net again.

Have to admit that MS really seems serious about this and is making a lot of the right sounds and saying a lot of the right things
With recent implementations they have even been matching up what they say with what they do pretty darned well

It’s encouraging

Here’s a project that creates:

ExportingAssemblyNE.dll for Windows and
ExportingAssemblyNE.dylib for MacOS

(NE stands for Native Exports)

If you look at the code it should be easy enough to understand how to call the functions, the ones named
Unmanagedxxx are the ones you would use.

e.g.

Declare Function UnmanagedVoidInt Lib "ExportingAssemblyNE.dll" As Integer
TextField1.Text = Str(UnmanagedVoidInt)

Trouble is, they don’t work with Xojo. Perhaps one of you much more knowledgable folks can determine why Xojo chokes on them?
Or perhaps see if they can be called from another app, like a C++ app maybe?

Xojo just complains “Function not found”…

Test Xojo app.

What version of VS are you using on Windows ?
Just for reference more than anything

edit - nm VS 2019 Community edition seems fine

That said there is a lot of stuff in the dylib that could be causing issues
There is a bunch of code in there that looks like its a runtime start up for managed code etc

I wonder if stripping everything down to just ONE unmanaged function and nothing else would be a better starting point
Possibly in this project just comment everything out except one unmanaged item to see if what lands in the dylib/dll is a LOT less and maybe that will help

Its a guess at this point

I can take a kick at this after I get some other work done so it might be a lot later tonight or tomorrow

VS 2019, but looks like you figured that one out! You’ll need the .NET5.0 preview 8 too.

Appreciate anything you are able to figure out. Man, if I could use C# libraries with my Xojo apps, I would be in heaven!

Sure but MOST of whats really useful in C# is in managed code which probably wont ever work as a DLL

Not as a helper app … thats a different story
I’m busy writing a stand a lone C# helper to launch edge with ANY url I want
It wont do that by default as a metro app on Windows 10

My understanding is that the way these Native Exports functions work is that they include all the managed code. Couldn’t care less if it’s managed or not, as long as I can call it from Xojo. SO many things that just work better in C#. Xojo for the X-Plat UI, C# for the “work”.

Helpers (which I presume you mean console apps?) aren’t that interesting to me - I want libraries that can manipulate large chunks of data at high speed (and multi-threaded) while the main app has access to all of it, passing pointers back and forth to data that both sides can manipulate.

Ports! I remember ports…