Hi,
I made a verry small dll as a test to see how i can use a pascal dll with C#.
The dll is:
library TestDLL;
{$mode objfpc}{$H+}
uses
Classes
{ you can add units after this };
function GetOne(): PChar; stdcall; export;
begin
Result := 'One';
end;
exports
GetOne;
begin
end.
The simple app in C# is:
[DllImport("TestDLL.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern string GetOne();
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = GetOne();
}
catch (Exception ex)
{
string tmp = "Just to read the exception when debugging";
}
}
When i debug i get first a strange message that the heap has been corrupted. When i continue the text "One" apears in the text box. This is not good. when i build and then execute the app crashes.
So i must do something wrong. Has anyone an idea how to create a dlle and use in in C#?