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/

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

最新文章

  1. 电脑桌面 IE 图标删除不了的解决方法
  2. 相克军_Oracle体系_随堂笔记012-undo
  3. javaScript封装的各种写法
  4. Python 与 meta programming
  5. Ajax返回中文乱码问题(未解决)
  6. Geek version acm pc^2 direction for user
  7. 转:Eric Lippert:阅读代码真的很难
  8. Windows 8.1 Update 2更新了什么?
  9. Windows桌面快捷方式图标全部变成同一个图标的解决方法
  10. html释疑
  11. Html.Action和Html.RederAction来创建子视图
  12. Django 反向生成 从数据库生成Model
  13. Spring + iBATIS完整示例
  14. Android实现屏蔽微信拉黑和删除联系人功能
  15. Socket中的异常和参数设置
  16. Oracle数据库------体系结构
  17. c语言的字符串
  18. Spring Cloud微服务实践之路- Eureka Server 中的第一个异常
  19. extern的使用详解(多文件编程)——C语言
  20. 浅析 Bigtable 和 LevelDB 的实现

热门文章

  1. shiro解析ini文件
  2. (读论文)推荐系统之ctr预估-NFM模型解析
  3. Linux之TCPIP内核参数
  4. linux下pip的安装
  5. 【React踩坑记三】React项目报错Can't perform a React state update on an unmounted component
  6. WebGL简易教程(二):向着色器传输数据
  7. Go中的反射reflect
  8. (16)ASP.NET Core 通用主机(HostBuilder)
  9. c# 多进程写信息到前台控件
  10. Oracle - SPM固定执行计划(一)