1

私のアプリケーションでは、stdcallを使用して、Delphi から DLL を作成する必要があります (より正確には、Lazarus IDE 内で記述された Delphi 互換コードであり、Linux でフリー パスカルによってコンパイルされます) 。
その DLL を (たとえば、Matlab などで) 使用する場合、もちろん、引数を渡すためのメタ情報が必要です。多くの場合、ヘッダー ファイルで実現されます。Delphi ソース コードで実行するツールを探しています。-リバースのようなh2pasもの。
私の研究では結果が得られませんでした。私が思うに、そのようなツールはありません。表またはその他の情報、Delphi/Pascal データ型が C 型にどのようにマッピングされるか、およびレコードを操作する方法を見つけたいと思います。

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 スイッチを使用した素晴らしい記事を書いています。

確かにすべてのタイプを処理できるわけではなく、かなりの数のHPPEMITおよびEXTERNALSYMディレクティブが必要になります。

当時の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 に答える