Hi,
Yes you are right of course. I made a simple application to demonstrate my
problem. It is containing only the nececary. I also made source for download
if that is more easy on
http://www.mestdagh.biz/kieken/CrashTest.zip The dll
I made for the demo is just calling the callback with the same data. this is
the complete project. Using the garbage collector I can let it reproduce the
error 1 on 2 times.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DllCrashDemo
{
public partial class Form1 : Form
{
private Api api;
public Form1()
{
InitializeComponent();
api = new Api(this);
api.OnShow += api_OnShow;
}
void api_OnShow(object sender, Api.ShowItArgs e)
{
listBox.Items.Add(e.text);
}
private void crashButton_Click(object sender, EventArgs e)
{
api.show("This is a crashtest");
}
}
public class Api
{
private Control owner;
public Api(Control control)
{
owner = control;
ApiDll.SetShow(cbShow);
}
public void show(string text)
{
ApiDll.ShowIt(text);
GC.Collect();
}
public class ShowItArgs : EventArgs
{
public string text;
}
public delegate void Show(object sender, ShowItArgs e);
public event Show OnShow;
private void cbShow(string text)
{
if (OnShow == null)
return;
ShowItArgs e = new ShowItArgs();
e.text = text;
owner.Invoke(OnShow, new object[] { this, e });
}
}
public static class ApiDll
{
private const string crashDllName = @"C:\Program
Files\Borland\Delphi7\Projects\CrashDll.dll";
public delegate void OnShow([MarshalAs(UnmanagedType.LPStr)]string
txt);
[DllImport(crashDllName)]
public static extern void
ShowIt([MarshalAs(UnmanagedType.LPStr)]string txt);
[DllImport(crashDllName)]
public static extern void SetShow(OnShow cbShow);
}
}