Delphi VS C语言类型转换对照

 
When converting C function prototypes to Pascal equivalent declarations, it's important to substitute the C function and argument types with the correct Pascal types.
I often use a Type Translation Table for this, like the following in table 1 (optional parts on the C-side are noted between square brackets):

C/C++ Type ObjectPascal Type
unsigned short [int] Word
[signed] short [int] SmallInt
unsigned [int] Cardinal { 3.25 fix }
[signed] int Integer
UINT LongInt { or Cardinal }
WORD Word
DWORD LongInt { or Cardinal }
unsigned long LongInt { or Cardinal }
unsigned long int LongInt { or Cardinal }
[signed] long LongInt
[signed] long int LongInt
char Char
signed char ShortInt
unsigned char Byte
char* PChar
LPSTR or PSTR PChar
LPWSTR or PWSTR PWideChar { 3.12 fix }
void* Pointer
BOOL Bool
float Single
double Double
long double Extended
   
LP,NP,PP,P prefix: if first = T then T becomes P else P prefix
   
HANDLE THandle
FARPROC TFarProc
ATOM TAtom
TPOINT TPoint
TRECT TRect
COLORREF TColorRef
OFSTRUCT TOFStruct
DEBUGHOOKINFO TDebugHookInfo
BITMAP TBitMap
RGBTRIPLE TRGBTriple
RGBQUAD TRGBQuad
BITMAPCOREHEADER TBitmapCoreHeader
BITMAPINFOHEADER TBitmapInfoHeader
BITMAPINFO TBitmapInfo
BITMAPCOREINFO TBitmapCoreInfo
BITMAPFILEHEADER TBitmapFileHeader
HANDLETABLE THandleTable
METARECORD TMetaRecord
METAHEADER TMetaHeader
METAFILEPICT TMetaFilePict
TEXTMETRIC TTextMetric
NEWTEXTMETRIC TNewTextMetric
LOGBRUSH TLogBrush
LOGPEN TLogPen
PATTERN TPattern { TLogBrush }
PALETTEENTRY TPaletteEntry
LOGPALETTE TLogPalette
LOGFONT TLogFont
ENUMLOGFONT TEnumLogFont
PANOSE TPanose
KERNINGPAIR TKerningPair
OUTLINETEXTMETRIC TOutlineTextMetric
FIXED TFixed
MAT2 TMat2
GLYPHMETRICS TGlyphMetrics
POINTFX TPointFX
TTPOLYCURVE TTTPolyCurve
TTPOLYGONHEADER TPolygonHeader
ABC TABC
RASTERIZER_STATUS TRasterizer_Status
MOUSEHOOKSTRUCT TMouseHookStruct
CBTACTIVATESTRUCT TCBTActivateStruct
HARDWAREHOOKSTRUCT THardwareHookStruct
EVENTMSG TEventMsg
WNDCLASS TWndClass
MSG TMsg
MINMAXINFO TMinMaxInfo
SEGINFO TSegInfo
ACCEL TAccel
PAINTSTRUCT TPaintStruct
CREATESTRUCT TCreateStruct
CBT_CREATEWND TCBT_CreateWnd
MEASUREITEMSTRUCT TMeasureItemStruct
DRAWITEMSTRUCT TDrawItemStruct
DELETEITEMSTRUCT TDeleteItemStruct
COMPAREITEMSTRUCT TCompareItemStruct
WINDOWPOS TWindowPos
WINDOWPLACEMENT TWindowPlacement
NCCALCSIZE_PARAMS TNCCalcSize_Params
SIZE TSize
MENUITEMTEMPLATEHEADER TMenuItemTemplateHeader
MENUITEMTEMPLATE TMenuItemTemplate
DCB TDCB
COMSTAT TComStat
MDICREATESTRUCT TMDICreateStruct
CLIENTCREATESTRUCT TClientCreateStruct
MULTIKEYHELP TMultiKeyHelp
HELPWININFO THelpWinInfo
CTLSTYLE TCtlStyle
CTLtype TCtltype
CTLINFO TCtlInfo
DDEADVISE TDDEAdvise
DDEDATA TDDEData
DDEPOKE TDDEPoke
DDEAACK TDDEAck
DEVMODE TDevMode
KANJISTRUCT TKanjiStruct

It's also nice to have access to the translation of the special WINDOWS.H types, which is already done by Borland, and can be found in WINTYPES.PAS (it's a rewarding experience to compare these two files with each other - you'll learn a lot about C and Pascal conversion issues).
Now that we've handled the standard built-in (and Windows) types, let's look at the C type definition of WING_DITHER_TYPE that is present in the WING.H file.

 typedef enum WING_DITHER_TYPE
{
WING_DISPERSED_4x4,
WING_DISPERSED_8x8,
WING_CLUSTERED_4x4
} WING_DITHER_TYPE;

This is a so -called enumerated type, and can be translated into an ObjectPascal enumerated type very easily:

 type
WING_DITHER_TYPE =
(WING_DISPERSED_4x4,
WING_DISPERSED_8x8,
WING_CLUSTERED_4x4);

While most C DLL header files contain only constant definitions (of the form #define XYZ value) and function prototypes, type definitions are also found,

and are therefore important to be able to convert.
 
 

作者:Jeremy.Wu
  出处:https://www.cnblogs.com/jeremywucnblog/

  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Delphi VS C语言类型转换对照的更多相关文章

  1. Delphi与C语言类型转换对照

    When converting C function prototypes to Pascal equivalent declarations, it's important to substitut ...

  2. php 、asp、 java、 c#、 delphi之间的语言对照

    PHP是一种跨平台的server端的嵌入式脚本语言.它大量地借用C,Java和Perl语言的语法, 并耦合PHP自己的特性,使WEB开发人员能够高速地写出动态产生页面. 它支持眼下绝大多数数据库. 另 ...

  3. Go 语言类型转换

    类型转换用于将一种数据类型的变量转换为另外一种类型的变量.Go 语言类型转换基本格式如下: type_name(expression) type_name 为类型,expression 为表达式. 实 ...

  4. Go语言类型转换

    类型转换用于将一种数据类型的变量转换为另外一种类型的变量. Go语言类型转换基本格式如下:表达式 T(v) 将值 v 转换为类型 T . Go语言各种类型转换及函数的高级用法:strconv包实现了基 ...

  5. GO语言学习(十七)Go 语言类型转换

    Go 语言类型转换 类型转换用于将一种数据类型的变量转换为另外一种类型的变量.Go 语言类型转换基本格式如下: type_name(expression) type_name 为类型,expressi ...

  6. C语言类型转换原理

    C语言类型转换 int a; a=1.23 这里把1.23赋值给a发生了隐式转换,原理如下: int a; float b=3.14; a=b; b赋值给a的过程:首先找一个中间变量是a的类型(该例中 ...

  7. C语言---类型转换

    itoa 功 能:把一整数转换为字符串 用 法:char *itoa(int value, char *string, int radix); 详细解释:itoa是英文integer to array ...

  8. c语言类型转换注意事项

    转载自: http://blog.csdn.net/zhuimengzh/article/details/6728492 1.隐式转换     C在以下四种情况下会进行隐式转换:        1.算 ...

  9. 执行效率做比较,Go、python、java、c#、delphi、易语言等

    比较环境,在win7   64位,比较各种语言的整数型运算,下面的比较只作为单项比较.具体方式,40000*40000遍历相加.为了防止编译器优化,生成一个随机数. 1:c#,在NET2.0框架下作为 ...

随机推荐

  1. Ansible CMDB

    Ansible CMDB CMDBAnsible-CMDB CMDB 文章目录 1. 简介 2. 安装 2.1. 1. 安装 ansible 2.2. 2. 下载并安装 ansible-cmdb 3. ...

  2. C#七种设计原则

    在C#中有七种设计原则 分别是 1.开闭原则(Open-Closed Principle, OCP) 2.单一职责原则(Single Responsibility Principle) 3.里氏替换原 ...

  3. 一份关于.NET Core云原生采用情况调查

    调查背景 Kubernetes 越来越多地在生产环境中使用,围绕 Kubernetes 的整个生态系统在不断演进,新的工具和解决方案也在持续发布.云原生计算的发展驱动着各个企业转向遵循云原生原则(启动 ...

  4. javaweb入门--web是什么

    WEB基本概念 首先明白web是什么,人们常说的web其实就是英文中页面的意思,准确来说是Internet主机供给外界访问的资源. 站在用户视角,也就是说,通过你浏览器(客户端)的地址栏输入资源(你要 ...

  5. Confluence未授权模板注入/代码执行(CVE-2019-3396)

    --- title: Confluence未授权模板注入/代码执行(CVE-2019-3396) tags: [poc,cve] num :g7y12 --- # 简介 --- Confluence是 ...

  6. 精准营销、批量提取QQ群成员号码

    有时我们在做精准营销时,需要从社群里提取群成员的QQ号,群发邮件,常规的做法是手工一个个复制粘贴,这样的效率无疑是很低的,下面我来分享一个批量获取社群的QQ号方法. 需要具备以下工具: 1.大量精准Q ...

  7. Ubuntu 系统如何用pycharm开发python—OpenCV

  8. c# 控制台console进度条

    1 说明 笔者大多数的开发在 Linux 下,多处用到进度条的场景,但又无需用到图形化界面,所以就想着弄个 console 下的进度条显示. 2 步骤 清行显示 //清行处理操作 int curren ...

  9. 解决:Navicat连接不上MySQL 8.0

    转载自 https://www.cnblogs.com/shiysin/p/shiysin.html Navicat连接不上,总是报错1251: 原因是MySQL8.0版本的加密方式和MySQL5.0 ...

  10. Linux部署项目遇到问题解决

    使用Linux部署web项目,可能会遇到各种各样问题导致服务启动失败,以下是我近期部署项目遇到的问题以及解决方案 一.场景:把war包放入tomcat的webapps文件夹下,然后启动tomcat服务 ...