I need to access a third party, .Net DLL that was written in C#. I found an old blog post from January 3, 2014 that shows how to convert it to a COM object so it can be accessed with Xojo. Unfortunately, I don’t know enough about C to convert the code for my use. This is the code from the blog.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace XojoStuff{
[Guid(“DB038D2E-BD4D-44A7-BE64-4844FF07F870”)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IManagedInterface { [DispId(1)] int PrintHi(string name); }
[Guid(“AB46D07F-6920-4114-924B-5E37BED3A65E”)]
[ClassInterface(ClassInterfaceType.None)]
public class InterfaceImplementation : IManagedInterface {
public int PrintHi(string name)
{ MessageBox.Show(name); return 1; } }
}
I used Regedit to find the dll which gives me the second GUID. I have no idea where I would find the first GUID.
I need to be able to send a string to the DLL that contains a command plus zero or more parameters and get back string with the value returned by the DLL which I believe requires modification to the “public interface” and “public class” lines above.
I am hoping that I can use something like
Var o As New XojoText.InterfaceImplemention
call o.DoFunction(“GetKWH(phase=1)”)
rather than having to implement each function of the DLL I might want to use such as
If it’s a COM object you might be able to bring it into Xojo by inserting it as an ActiveX component. I’ve had mixed results with this in Xojo, sometimes the code that is generated has the wrong datatypes so you might need to do some tinkering. Have you tried this approach?
If its your C# object or object you have the source code for then you can put attributes in it so that it gets COM wrapper built into it.
If its not object you own then you can make your own C# object that wraps the other one where your object would then register it self as COM object with the correct attributes.
How good or nice or bad its to talk to COM object in Xojo I dont know though.