D
Daniel W.
Hello, I'm trying to create this DLL that will get called from a
Delphi program. In order to interface the unmanaged Delphi program
with the managed C#, I'm trying to make an intermediary bridge DLL. So
far I've been able to make it accessible to the Delphi program, but
I'm having problems returning a string which is passed as a pchar
parameter.
Delphi signature for the function I'm implementing:
function ElectronicPay(const input
char, var output
char):
boolean; export; stdcall;
C# bridge implementation so far:
[DllExport] // http://www.codeproject.com/KB/dotnet/DllExporter.aspx?msg=3267441
public unsafe static bool ElectronicPay(string input, IntPtr
output)
{
string managedOutput = Marshal.PtrToStringAnsi(output);
Terminal.ElectronicPay(input, ref managedOutput);
output = Marshal.StringToHGlobalAnsi(managedOutput);
return true;
}
Now the input string works perfectly. However I'm having problems with
producing the output. I'm pretty sure I'm not supposed to allocate the
memory for output, but rather use what they should have given me
already preallocated. However I haven't been able to get the string
they are sending in in the output parameter. Can anybody shine some
light on how to deal with this situation. Please note that I don't
have any control nor source code of the Delphi program.
Thanks.
Dan
Delphi program. In order to interface the unmanaged Delphi program
with the managed C#, I'm trying to make an intermediary bridge DLL. So
far I've been able to make it accessible to the Delphi program, but
I'm having problems returning a string which is passed as a pchar
parameter.
Delphi signature for the function I'm implementing:
function ElectronicPay(const input
![Stick Out Tongue :p :p](/styles/default/custom/smilies/tongue.gif)
![Stick Out Tongue :p :p](/styles/default/custom/smilies/tongue.gif)
boolean; export; stdcall;
C# bridge implementation so far:
[DllExport] // http://www.codeproject.com/KB/dotnet/DllExporter.aspx?msg=3267441
public unsafe static bool ElectronicPay(string input, IntPtr
output)
{
string managedOutput = Marshal.PtrToStringAnsi(output);
Terminal.ElectronicPay(input, ref managedOutput);
output = Marshal.StringToHGlobalAnsi(managedOutput);
return true;
}
Now the input string works perfectly. However I'm having problems with
producing the output. I'm pretty sure I'm not supposed to allocate the
memory for output, but rather use what they should have given me
already preallocated. However I haven't been able to get the string
they are sending in in the output parameter. Can anybody shine some
light on how to deal with this situation. Please note that I don't
have any control nor source code of the Delphi program.
Thanks.
Dan