0

I have a c# class that connects to the dll that works good.

Now I need the same functions in Delphi. what is the best way to do it? I don't want to write all the imports again in Delphi. is there a way to import the c# class in delphi or any other way of doing that quick and easy..

This is one function in my c# class:

    /// Return Type: ABS_STATUS->ABS_LONG->int
    ///pszDsn: ABS_CHAR*
    ///phConnection: ABS_CONNECTION*
    [System.Runtime.InteropServices.DllImportAttribute("bsapi.dll", EntryPoint = "ABSOpen", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    public static extern int ABSOpen([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pszDsn, ref uint phConnection);
Ezi
  • 2,212
  • 8
  • 33
  • 60

1 Answers1

1

That's simple in Delphi:

function ABSOpen(pszDsn: PAnsiChar; var phConnection: Cardinal): Integer; 
    stdcall; external 'bsapi.dll';

You'll no doubt have more functions than this, but they should all be easy enough. If I were you I would go back to the original C++ header file which should be much easier to translate than your p/invokes.

I don't think there is any good conversion tool for p/invoke to Delphi import unit. Even for C++ header to Delphi, I'm not convinced that there is good universal tool. You can look at the JEDI project which has some useful resources, but in my view it's time to roll up your sleeves!

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490