0

The delphi dll code like this:

function TCP_CHECKOUT(const RoomName:string; ClearCard:boolean):Byte

when I call it in c#,but always get the error return code. My c# code like this:

[DllImport(@"EHLKEY.dll", EntryPoint = "TCP_CHECKOUT")]
public extern static Byte TCP_CHECKOUT(string RoomName, bool ClearCard);

The delphi code user said the return code 255 is not call success.Somebody can help me to solve it?Thanks!

J.Yang
  • 11
  • The Delphi code is wrong. Delphi's `string` is not appropriate for interop, and neither is `boolean`. Contact the author of the DLL and tell them to use appropriate types for the parameters. – Ken White Feb 25 '17 at 03:49
  • Delphi's calling convention is not MS fastcall. This function can't be called from c#. You'll need to change the Delphi code to allow that. – David Heffernan Feb 25 '17 at 05:07
  • @KenWhite Any other method to avoid this misstake?Can I use c++ or others to call it,then use the middleware in c#. – J.Yang Feb 25 '17 at 05:27
  • @DavidHeffernan You are right.Any other method to solve this problem? – J.Yang Feb 25 '17 at 05:29
  • If you can't change the Delphi code then you may need a delphi wrapper in the middle to act as an adapter. But even that might fail if the memory management is handled wrongly by the DLL. Not enough information here to be sure. – David Heffernan Feb 25 '17 at 05:31
  • Sure. Write your own Delphi DLL to act as middleman to correct the errors. Better to just have the author fix the issues rather than inject another layer of cruft, though. You can't just use a different non-Delphi language to fix problems caused by Delphi code that uses wrong types and calling conventions. – Ken White Feb 25 '17 at 05:36
  • @KenWhite: Yeah, I am so dumb. Deleted comment. – apocalypse Feb 25 '17 at 06:36

0 Answers0