Using DLL's

I’m working on trying to migrate a C# application to Xojo, this application has a client which connects to a 3D rendering application and passes messages and receives a reply.
Rather than try to re create the client in Xojo it seemed a lot easier to just create a DLL seeing as I’m very much a newbie with Xojo
I spend most of last night trying to get it working but failed dismally :confused:
The dll is called ClassLibrary1.dll

In C# it does the following by clicking a button on the main form:

[code]using ClassLibrary1;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

    }
    string ipadd = "localhost";
        int portadd = Int32.Parse("6300");

    private void button1_Click(object sender, EventArgs e)
    {
        Class1 cl = new Class1();
        String strData = "message \"Render\"";
        cl.Clientx(strData, ipadd, portadd);
        
    }
}

}[/code]

In Class1 we have

[code]namespace ClassLibrary1
{
public class Class1
{
public void Clientx(String strData, string ipadd, int portadd)
{
//All the client stuff goes here

}
}
[/code]

When I tried last night I could find the DLL but it couldn’t find Clientx
Anyway I hope my ramblings make sense lol
thanks

The DLL must export C functions. You can’t import classes into xojo without plugin.
For declares you can only use C functions.

[quote=121544:@nige cope]'m working on trying to migrate a C# application to Xojo, this application has a client which connects to a 3D rendering application and passes messages and receives a reply.
Rather than try to re create the client in Xojo it seemed a lot easier to just create a DLL [/quote]

Have you checked https://forum.xojo.com/7079-using-c-classes-in-xojo/23#p121569

Is it possible to use C# DLL files from straight C in order to make a Xojo wrapper?

Thanks for the link Michel, I’ll give it a go :slight_smile:

Thanks for your help it is now working, now I need to add a few more things and the client is good to go :slight_smile:

Sorry to drag this back up
In Xojo I have

Declare Function Clientx lib "C:\\Users\ ige\\Desktop\\realprojects\\ClassLibrary1.dll" (strData as CString, portadd As integer, ipadd as CString, response as CString ) AS CString

In the DLL

 public static int Clientx(String strData, int portadd, string ipadd, out string response) 

the problem I’m having is the “out string response” this is the reply from the DLL, if I take the “out” out it does work but no response back, which I need

I am not very savvy in C, but since the out string works, what about adding another string parameter to get the response ?

out is to output the response string
strData is the message to send
portadd, is the port
ipadd Is the ip
response is the server output

I don’t usually do dll’s either so there’s probably a different way
Thanks Marcel

[quote=128827:@nige cope]out is to output the response string
strData is the message to send
portadd, is the port
ipadd Is the ip
response is the server output

I don’t usually do dll’s either so there’s probably a different way
Thanks Marcel[/quote]

From what I understand response works well to send from the dll but what you need is that Xojo sends back to the Dll, and that is where it fails ?

in its simplest form, you would click a button in Xojo to send the strData message to the dll, so say it sends “version” to the server the response back will be “v1.3.07.1130” which I need to see in Xojo
IF I don’t have the “out” in the DLL, the message is send and Thea will carry out the command however I can’t get the response back in Xojo
The response back is very useful, the client can interact with Thea , in fact you can control the whole thing remotely, the response can control timers, visually see render progress elapse time, passes,its quite cool when it works lol

Its always a difficult one, the client is only useful with Thea, I don’t have a straight C version or a VB one. as a reference

But I’m almost there I just need to think of a different way to get rid of the out statement

[quote=128835:@nige cope]in its simplest form, you would click a button in Xojo to send the strData message to the dll, so say it sends “version” to the server the response back will be “v1.3.07.1130” which I need to see in Xojo
IF I don’t have the “out” in the DLL, the message is send and Thea will carry out the command however I can’t get the response back in Xojo
The response back is very useful, the client can interact with Thea , in fact you can control the whole thing remotely, the response can control timers, visually see render progress elapse time, passes,its quite cool when it works lol

Its always a difficult one, the client is only useful with Thea, I don’t have a straight C version or a VB one. as a reference

But I’m almost there I just need to think of a different way to get rid of the out statement[/quote]

My suggestion was simply to add another parameter dedicated to give the response back to Xojo. Since you are in control of both the DLL and the calling Xojo program, it seems the easiest way.

I’m totally lost,
I’ve been searching the net and as far as the dll goes

public static int Clientx(String strData, int portadd, string ipadd, out string  response)

is right and quite common

out or ref

are the way this is usually handled and works fine with the Visual Studio

Anyway I need a break lol

First, your Declare doesn’t match your function. Second, to receive a string back from a dll, declare the string as Ptr and pass it a MemoryBlock. So

Declare Function Clientx lib "C:\\Users\ ige\\Desktop\\realprojects\\ClassLibrary1.dll" (strData as CString, portadd As integer, ipadd as CString, response as Ptr) AS Integer
Call it with

dim data as string
dim portadd as integer
dim ipadd as string
dim mresponse as memoryblock
dim response as string
dim ret as integer
...
ret = Clientx(data, portadd, ipadd, mresponse)
response = mresponse.CString(0)

Thanks Tim, I’ll give it a try