如何为Delphi/Free Pascal/Lazarus DLL创建C-Header-数据类型
对于我的应用程序,我需要使用stdcall从Delphi创建一个DLL(更准确地说,是在linux下由免费pascal编译的Lazarus IDE中编写的与Delphi兼容的代码)。如何为Delphi/Free Pascal/Lazarus DLL创建C-Header-数据类型,c,delphi,dll,header-files,stdcall,C,Delphi,Dll,Header Files,Stdcall,对于我的应用程序,我需要使用stdcall从Delphi创建一个DLL(更准确地说,是在linux下由免费pascal编译的Lazarus IDE中编写的与Delphi兼容的代码)。 当使用该DLL(例如在Matlab中)时,当然需要传递参数的元信息——通常通过头文件实现。 我正在寻找一个工具,可以在delphi源代码上运行。类似于h2pas-反向。 我的研究没有结果。我认为,没有这样的工具,我想找到一个表或其他信息,如何将delphi/PASCAL数据类型映射到C类型以及如何处理记录。 < P
当使用该DLL(例如在Matlab中)时,当然需要传递参数的元信息——通常通过头文件实现。 我正在寻找一个工具,可以在delphi源代码上运行。类似于
h2pas
-反向。我的研究没有结果。我认为,没有这样的工具,我想找到一个表或其他信息,如何将delphi/PASCAL数据类型映射到C类型以及如何处理记录。 < P>我使用下面的构造来生成与Delphi 5代码中C模式C++编译器兼容的头文件,当Delphi有-JPH切换时(见下面的注释) 请注意,我从Delphi 5开始就没有使用过此选项,但此后开关已扩展: 在该行的某个地方,已将添加到
dcc32
命令行编译器中:
-JPHNE = Generate C++ .obj file, .hpp file, in namespace, export all
鲁迪·韦尔图伊斯有一个朋友
它当然不能处理所有类型,您将需要相当多的命令和指令
我把我的文件上传到了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}
VisualC++ 6不喜欢嵌套结构/结合方式,而BC+++则可以处理它们。
Visual C++ 6需要“TyPulf”和结构定义后的类型名。
在定义TConversationId、TReturnKey和其他依赖嵌套结构/联合的类型时,您将看到这一点
诀窍是每次更换此装置时都要执行以下步骤:
-在禁用所有EXTERNALSYM的情况下生成此单元一次。
-然后DCC32-JPH将为它们生成基本结构。
-将所有嵌套的结构和联合定义复制到此文件
-将定义嵌入(*$HPPEMIT“”*)
-将typename追加到结构定义的末尾
-再次启用所有外部符号
-使用DCC32-JPH重新生成HPP文件
为了简化此过程,我们引入了两个新的条件定义:
-BCB-禁用外部SYM,禁用HPPEMIT
-VC6-启用外部SYM,启用HPPEMIT
类似的情况是,VC6也不喜欢这些结构:
-短字符串(BCB将其定义为VC6不喜欢的“SmallString”)。
-短整数(BCB将其定义为“Shortint”,因此我们为此提供了一个HPPEMIT)
}
{$ifdef win32}
{重要!确保所有枚举的类型每个正好适合一个字节!}
{$Z1}
{强制C/C++HPP头文件在字节边界上具有C/C++编译器包结构元素}
{$ifdef BCB}
{$HPPEMIT'#pragma选项推送-a1'}
{$endif BCB}
{$endif win32}
< Delphi有-JPH切换(见下面的注释),我使用下面的构造生成与Delphi 5代码中的Visual C++ 6的C模式编译器兼容的头文件。 请注意,我从Delphi 5开始就没有使用过此选项,但此后开关已扩展: 在该行的某个地方,已将添加到
dcc32
命令行编译器中:
-JPHNE = Generate C++ .obj file, .hpp file, in namespace, export all
鲁迪·韦尔图伊斯有一个朋友
它当然不能处理所有类型,您将需要相当多的命令和指令
我把我的文件上传到了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}
VisualC++ 6不喜欢嵌套结构/结合方式,而BC+++则可以处理它们。
Visual C++ 6需要“TyPulf”和结构定义后的类型名。
在定义TConversationId、TReturnKey和其他依赖嵌套结构/联合的类型时,您将看到这一点
诀窍是每次更换此装置时都要执行以下步骤:
-在禁用所有EXTERNALSYM的情况下生成此单元一次。
-然后DCC32-JPH将为它们生成基本结构。
-将所有嵌套的结构和联合定义复制到此文件
-将定义嵌入(*$HPPEMIT“”*)
-将typename追加到结构定义的末尾
-再次启用所有外部符号
-使用DCC32-JPH重新生成HPP文件
为了简化此过程,我们引入了两个新的条件定义:
-BCB-禁用外部SYM,禁用HPPEMIT
-VC6-启用外部SYM,启用HPPEMIT
类似的情况是,VC6也不喜欢这些结构:
-短字符串(BCB将其定义为VC6不喜欢的“SmallString”)。
-短整数(BCB将其定义为“Shortint”,因此我们为此提供了一个HPPEMIT)
}
{$ifdef win32}
{重要!确保所有枚举的类型每个正好适合一个字节!}
{$Z1}
{强制C/C++HPP头文件在字节边界上具有C/C++编译器包结构元素}
{$ifdef BCB}
{$HPPEMIT'#pragma选项推送-a1'}
{$endif BCB}
{$endif win32}
Integer--int,Double--Double,Single--float,Byte--char,record--struct。你想要更多吗?谢谢@DavidHeffernan-这是一个非常酷的开始。有时我需要基数-这映射到无符号长吗?不。它是无符号int。如果你在Linux上,你的长将是64位,对吗?注意,整数--int,Double--Double,Single--float,Byte--char,record--struct。你想要更多吗?谢谢@DavidHeffernan-这是一个非常酷的开始。有时我需要基数-这映射到无符号长吗?不。它是无符号int。如果你在Linux上,你的长将是64位,对吗?注意,DLL是用FreePascal编写的,不是Delphi。FielasCar不支持C++,AFAIK对Delphi的C++输出开关没有等效的功能。