I have a situation where I need to create an unmanaged DLL in .Net, which can be called from the delphi program. I did some research and I found the Robert Gieseke library (RGiesecke.DllExport). I started with a pretty simple DLL that displays the shape of a window with a text box, something like this:
[ComVisible(true)]
[DllExport("PlaceOrder", CallingConvention = CallingConvention.StdCall)]
public static IntPtr PlaceOrder(IntPtr lnpInXml)
{
string inputXml = Marshal.PtrToStringAnsi(lnpInXml);
StringBuilder sbOutputXml = new StringBuilder();
Form1 pti = new Form1(inputXml, sbOutputXml);
pti.ShowDialog();
return Marshal.StringToHGlobalAnsi(sbOutputXml.ToString());
}
This works fine, I configure the delphi program to call my DLL, and it works fine. The problem arises when I add a link to another project in my solution and create an instance of the object inside this project. At this point, the delphi program stops displaying the form, because it cannot find the exported function, but it also does not cause any errors:
using MyCommonCode;
namespace UnmanagedDLLTest
{
[ComVisible(true)]
public static class UnmanagedDLL
{
[ComVisible(true)]
[DllExport("PlaceOrder", CallingConvention = CallingConvention.StdCall)]
public static IntPtr PlaceOrder(IntPtr lnpInXml)
{
string inputXml = Marshal.PtrToStringAnsi(lnpInXml);
StringBuilder sbOutputXml = new StringBuilder();
Form1 pti = new Form1(inputXml, sbOutputXml);
pti.ShowDialog();
MyCommonCode.MyClass mc = new MyCommonCode.MyClass();
return Marshal.StringToHGlobalAnsi(sbOutputXml.ToString());
}
}
}
This line:
MyCommonCode.MyClass mc = new MyCommonCode.MyClass();
, , . , google, , , . , , : (.
.