0

我有连接到运行良好的 dll 的 ac# 类。

现在我在 Delphi 中需要相同的功能。最好的方法是什么?我不想在 Delphi 中再次编写所有导入。有没有办法在delphi中导入c#类或任何其他快速简便的方法..

这是我的 c# 类中的一个函数:

    /// 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);
4

1 回答 1

1

这在德尔福很简单:

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

毫无疑问,您将拥有比这更多的功能,但它们都应该足够简单。如果我是你,我会回到原来的 C++ 头文件,它应该比你的 p/invokes 更容易翻译。

我认为 p/invoke 到 Delphi 导入单元没有任何好的转换工具。即使对于 Delphi 的 C++ 头文件,我也不相信有很好的通用工具。你可以看看JEDI 项目,它有一些有用的资源,但在我看来,是时候卷起袖子了!

于 2012-04-19T18:25:51.760 回答