Hello,
trying to combine a ClearWin+ application, which uses a callback on a Quit button, with some interface to a .NET library. Both things are unrelated at the moment, that is the call to a .NET routine is separate from the ClearWin+ code.
In general it works fine, the .NET subroutine is called, and the ClearWin+ window is created. If the .NET subroutine contains more complex memory operations, or, which is relevant, a plain call to the garbage collector, the ClearWin+ callback ceases to work. The errormessage translates to something like 'CallbackOnCollectDelegate was found' which seems to indicate that the garbage collector removed (?) the callback function, and ftn95lib.mdl!Salford.Fortran.RTLibrary+clearwin_callback::Invoke fails.
Some steps to reproduce this:
Create new Project, FTN95 Application Add another project: File, Add, New Project Choose C# Class Library for example In the project settings assure that the FortranApplication is the start project. Also make the ClassLibrary project a dependency of the FortranApplication
Add the ClassLibrary to the References of the FortranApplication.
Code for the fortran part:
INTEGER FUNCTION cb_quit()
IMPLICIT NONE
cb_quit = 0
END FUNCTION
PROGRAM Main
IMPLICIT NONE
EXTERNAL cb_quit
INTEGER cb_quit, iw
ASSEMBLY_EXTERNAL(NAME='ClassLibrary1.Class1.class_test_routine') &
class_test_routine
OBJECT('ClassLibrary1.Class1') CLASS1
CLASS1 = NEW@('ClassLibrary1.Class1')
CALL class_test_routine(CLASS1)
iw = winio@('%^bt[&Quit]', cb_quit)
END
Code for the c# part:
using System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public void class_test_routine()
{
// GC.Collect();
const int max_lp = 100;
int[][] test = new int[max_lp][];
for (int ct = 0; ct < max_lp; ct++)
{
test[ct] = new int[65536];
}
}
}
}
The error might or might not occur with the int[] allocation as above, it seems to depend on the garbage collector's properties (memory size?), but forcing the collector to run via GC.Collect() always results in the bug.
I've already tried quite a lot of things, like encapsulating the ClearWin+ code in a module, but couldn't get it working. Any help or hints appreciated.
Thanks.