Call back to Clarion from a .Net control

This is a continuation of a longer conversation on Skype, with reference to a ClarionLive webinar and example code by @hdsoftware

I managed to get your demo code (SQLQuery) to call back to clarion it was a matter of using the runtime AttachThreadToClarion call from the control itself, then just pass in the procedure/s you want to call back.

So in the global cs file I have

public delegate void CallbackProc();
static CallbackProc callbackProc;

Then in the initiate procedure in the global cs file changed to and added a calling procedure

 [DllExport("SQLQueryTool_Initiate", CallingConvention = CallingConvention.StdCall, ExportName = "SQLQueryTool_Initiate")]
 public static void SQLQueryTool_Initiate(int SQLQueryToolWrapperHandle, CallbackProc cb)
 {
     callbackProc = cb;
     Controls.SQLQueryTool.CreateControl(SQLQueryToolWrapperHandle, new Controls.SQLQueryTool());
 }
[DllImport("ClaRun.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "AttachThreadToClarion")]
        public static extern void AttachThreadToClarion(int allocateThread);
public static void callCallback()
{
     AttachThreadToClarion(1);
     callbackProc();
 }

Then from the form just call the global callCallback method