1

For my application I need to create a DLL from Delphi (to be more precise Delphi compatible code written within Lazarus IDE compiled by free pascal under linux) using stdcall.
When using that DLL (for example in Matlab or so) one needs of course the meta information for passing the arguments - often realised with a header file. I'm searching for a tool do to that running on the delphi source code. Something like h2pas-reverse.
My research yielded no results. As I think, there is no such tool, I'd like to find a table or other information, how the Delphi/Pascal data types are mapped to C types and how to work with records.

4

1 回答 1

1

当 Delphi 有 -JPH 开关时,我已使用以下构造从 Delphi 5 代码生成与 Visual C++ 6 的 C 模式编译器兼容的头文件(请参阅下面的注释)。

请注意,自 Delphi 5 以来我没有使用过这个,但此后该开关已被扩展:

在某个地方,JPHNE 开关已添加到dcc32命令行编译器中:

  -JPHNE = Generate C++ .obj file, .hpp file, in namespace, export all

Rudy Velthuis 有一篇使用 JPHNE 开关的好文章

它当然不能处理所有类型,您将需要相当多的HPPEMITEXTERNALSYM指令。

我上传了我的Delphi 5 到 Visual C++ 6 HPP 的转换,从那时到 BitBucket。

它生成 .hpp 文件以导入用 Delphi 编写的 DLL。

Delphi 5 时代的笔记:

{ Visual C++ 6 does not like nested structs/unions the way that BC++ can handle them.
  Visual C++ 6 requires the "typedef" to be present AND the typename AFTER the struct definition.
  You will see this when defining TConversationId, TReturnKey and other types that depend on nested structs/unions

  The trick is to perform these steps each and every time this unit changes:
    - Generate this unit once with all the EXTERNALSYM disabled.
      - Then the DCC32 -JPH will generate the basic structs for them.
    - Copy all the nested struct and union definitions to this file
    - Embed the definitions with (*$HPPEMIT '' *)
    - Append the typename at the end of the struct definition
    - Enable all the EXTERNALSYM again
    - Regenerate the HPP files by using DCC32 -JPH
  To make this process easier, we have introduced two new conditional defines:
    - BCB - disable EXTERNALSYM, disable HPPEMIT
    - VC6 - enable EXTERNALSYM, enable HPPEMIT

  A similar thing is with these constructions that VC6 does not like those either:
    - short strings (BCB defines them as "SmallString<##>" which VC6 does not like).
    - short integers (BCB defines them as "Shortint" so we have included an HPPEMIT for that)
}

{$ifdef win32}
  { important! Makes sure that the all enumerated types fit in exactly one byte each! }
  {$Z1}

  { force the C/C++ HPP header files to have the C/C++ compiler pack structure elements on byte boundaries }
  {$ifdef BCB}
    {$HPPEMIT '#pragma option push -a1' }
  {$endif BCB}
{$endif win32}
于 2013-09-11T11:42:56.130 回答