I thought I would update this thread by pasting in C# JEXEServer code that
compiles and works just fine in the free Express 2008 Edition of C#.
The trick to getting this to work is to only create one instance of the
JEXEServer and let the C# garbage collector cleanup. This snippet of code
lacks the general approach of Alex Rufon's class but is so simple that
anyone can follow and use it.
Cheers
// C# code starts here.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class HelloJForm : Form
{
private JEXEServerLib.JEXEServer jObject;
private int jShowToggle = 0;
public HelloJForm()
{
// J return code 0 is success nonzero J error
int rc;
InitializeComponent();
// create and load J server object
jObject = new JEXEServerLib.JEXEServer();
// set J to quit when the parent quits
// let the garbage collector clean up jObject
rc = jObject.Quit();
// J input logging on
rc = jObject.Log(1);
// set some internal J nouns
rc = jObject.Do("BINPATH_z_=:1!:46''");
rc = jObject.Do("ARGV_z_=:,<'CSHARP HACK'");
// load the profile
rc = jObject.Do("0!:0 <BINPATH,'\\profile.ijs'");
// hide J window
rc = jObject.Show(0);
jShowToggle = 0;
}
private void button1_Click(object sender, EventArgs e)
{
object jout;
string jstr;
int rc;
jstr = "String from J -> ";
textBox.Text = jstr;
jObject.Do("jRes=. \":400?400");
rc = jObject.GetB("jRes", out jout);
jstr = (string)jout;
textBox.Text += jstr;
}
private void button2_Click(object sender, EventArgs e)
{
if (jShowToggle == 1)
{
jObject.Show(0);
jShowToggle = 0;
this.button2.Text = "Show J";
}
else
{
jObject.Show(1);
jShowToggle = 1;
this.button2.Text = "Hide J";
}
}
}
}
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm