I have atteched 3 programs where a C# program calls 2 O2 dlls
which can pass parameters to each other and back.
C# program GitO2data.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// need this to run DllImport
using System.Runtime.InteropServices;
namespace GitO2Data
{
public partial class Form1 : Form
{
// Note that this program is compiled to 64 bits while its O2 dlls are also compiled to 64 bits
// setup the DLLs
[DllImport("DllMain.DLL", EntryPoint = "RetString")]
[return: MarshalAs(UnmanagedType.AnsiBStr)]
public static extern string RetString([MarshalAs(UnmanagedType.AnsiBStr)]
ref string Seltxt);
// reference https://stackoverflow.com/questions/16332701/how-to-call-c-dll-in-c-sharp
[DllImport("Greet.dll", EntryPoint = "greet")]
public static extern int greet(string rfst);
public Form1()
{
InitializeComponent();
}
// Button to get Message from an O2 DLL
private void button1_Click(object sender, EventArgs e)
{
// display the greeting
string txtmynam = "Good Man";
int dummynum = greet(txtmynam);
MessageBox.Show(" number from O2 : " + dummynum.ToString() );
}
// Button to get a string from an O2 DLL
private void button2_Click(object sender, EventArgs e)
{
string txtReturn = "";
// Obtain the entered text
string EnterText = textBox1.Text.Trim();
// get the return string
txtReturn = RetString(ref EnterText);
// Display the return string on the screen
MessageBox.Show(" String from O2 dll : " + txtReturn);
}
}
}
and the Dllmain.o2bas (thanxx to Charles )
% dll
% filename "DllMain.dll"
uses rtl64
def TRIM ltrim(rtrim(%1))
function RetString(stwant as string) as string, export
If LCASE(TRIM(stwant)) = "one" then
return "First string (one) was entered"
else
return " Other string was entered"
end if
end function
the Greet.o2bas (thanxx to Charles )
% dll
% filename "Greet.dll"
uses rtl64
function greet(stgreet as char) as long, export
print "hello "+stgreet
return 1
end function