I am evaluating Xojo for developing a commercial web app, and I understand it is possible to use some C# classes that I have already developed. These C# classes have no user interface - they are just inter-related classes that carry out calculations, and that read and write to and from a Mongo database.
Please can somebody describe how I can use my C# classes in Xojo?
I am trying to find out:
what kind of project should my C# classes be contained or wrapped in? E.g. is it a Class Library, with “Make assembly COM-Visible” ticked? Or something else?
what kind of classes do they need to be? E.g. I assume they need to be public classes - are they any other requirements?
what other properties do I need to check or set in my Visual Studio project, to make it usable within Xojo? E.g. do I need “Register for COM interop” ticked?
what do I need to do outside of Visual Studio or Xojo, to make it possible to see and use my C# classes from within Xojo? E.g. do I need to use regsvr32, or regasm, and with what parameters?
what do I need to do in Xojo to be able to instantiate and use my C# classes? E.g. should I use Insert > ActiveX Component, and look on the Components tab, or the References tab?
I have tried out a few things, from searching the forums and the internet, but none of it seem to work, in the sense that I cannot see my C# library on either tab of the Insert > ActiveX Component command.
I am using Xojo version 2013, release 3.3, and Microsoft Visual Studio 2012 Ultimate, update 4. I’m using 64-bit Windows 7 Professional, service pack 1.
I’ve seen this question a few times and thought I would respond with an answer.
Xojo makes this really easy for you. And heres how you do it (quick and easy version):
Create a Class Library project in C# (I use VS C# Express 2010).
Here is a VERY simple example of a c# project file, with the correct attributes and interfaces:
[code]using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyXojoToDotNetClassLibrary
{
[Guid(“DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05”)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IManagedInterface
{
[DispId(1)]
int PrintHi(string name);
}
[Guid(“C6659361-1625-4746-931C-36014B146679”)]
[ClassInterface(ClassInterfaceType.None)]
public class InterfaceImplementation : IManagedInterface
{
public InterfaceImplementation()
{
}
public int PrintHi(string name)
{
MessageBox.Show(name);
return 1;
}
}
}
[/code]
Make sure your target platform is x86
check the “Register for Com interop” checkbox in the project build settings. Alternatively you can use the command line tool regasm to register it for you outside of VS (regasm -tlb -codebase MyClassLibrary.dll for example)
Make sure you are running Visual Studio as Administrator (or running a command prompt as administrator if you use regasm)
build your C# project.
Create a new Xojo desktop Project (I’m using 2013.3r3)
Go to insert menu, then ActiveX Component, references tab. find and click on the class you made in Visual Studio. In My case, it was called “MyClassLibrary”. Xojo will generate a new module and some classes needed to interop with COM.
In a button->action event on your Xojo window add the following:
dim o as new MyClassLibrary.InterfaceImplementation
Call o.PrintHi("Hello from .NET!!!!!!")
You should see a message box pop up with your message. You could easily expand this to open .net forms, open xaml forms, interoperate with a database that .NET supports etc.
There are additional complexities in dealing with events, callbacks and such however this should get you started.
Ohh, hehe, and one more thing! you will want to use your own GUIDs in any C# code you write. VS can generate them or you can go to http://createguid.com/ to get one.
I think this should serve to tell you how versatile Xojo is. If you are on windows (XP, Windows 7, WIndows 8.x)), you can access anything .net has to offer as well. I’ve never run into a limitation with Xojo that I couldn’t work around in some fashion.
I can’t say for sure, but as long as your not going to try to embed one of their controls into a Xojo window, you should be fine. Just create the create the form in c# and show it from there.
I’ve been looking for something like this (and my Windows Xojo post last week) I make mention about how important it is to get access to the .NET side… Can Paul or someone at Xojo take a look into this to see if there’s some documentation that could come out of this for the folks (like myself) who could use this?
Yes, I will be looking into Jim’s example to see if I can get something into the docs. I just have to get Visual Studio set up in a VM. As we all know, it takes a wee bit longer to install Visual Studio than it does to install Xojo!