Delphi与C语言类型转换对照

Delphi与C语言类型转换对照  

2010-10-06 20:53:49|  分类:默认分类 |  标签:|字号 订阅

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++ TypeObjectPascal Type
unsigned short [int]Word
[signed] short [int]SmallInt
unsigned [int]Cardinal { 3.25 fix }
[signed] intInteger
UINTLongInt { or Cardinal }
WORDWord
DWORDLongInt { or Cardinal }
unsigned longLongInt { or Cardinal }
unsigned long intLongInt { or Cardinal }
[signed] longLongInt
[signed] long intLongInt
charChar
signed charShortInt
unsigned charByte
char*PChar
LPSTR or PSTRPChar
LPWSTR or PWSTRPWideChar { 3.12 fix }
void*Pointer
BOOLBool
floatSingle
doubleDouble
long doubleExtended
  
LP,NP,PP,P prefix: if first = T then T becomes P else P prefix
  
HANDLETHandle
FARPROCTFarProc
ATOMTAtom
TPOINTTPoint
TRECTTRect
COLORREFTColorRef
OFSTRUCTTOFStruct
DEBUGHOOKINFOTDebugHookInfo
BITMAPTBitMap
RGBTRIPLETRGBTriple
RGBQUADTRGBQuad
BITMAPCOREHEADERTBitmapCoreHeader
BITMAPINFOHEADERTBitmapInfoHeader
BITMAPINFOTBitmapInfo
BITMAPCOREINFOTBitmapCoreInfo
BITMAPFILEHEADERTBitmapFileHeader
HANDLETABLETHandleTable
METARECORDTMetaRecord
METAHEADERTMetaHeader
METAFILEPICTTMetaFilePict
TEXTMETRICTTextMetric
NEWTEXTMETRICTNewTextMetric
LOGBRUSHTLogBrush
LOGPENTLogPen
PATTERNTPattern { TLogBrush }
PALETTEENTRYTPaletteEntry
LOGPALETTETLogPalette
LOGFONTTLogFont
ENUMLOGFONTTEnumLogFont
PANOSETPanose
KERNINGPAIRTKerningPair
OUTLINETEXTMETRICTOutlineTextMetric
FIXEDTFixed
MAT2TMat2
GLYPHMETRICSTGlyphMetrics
POINTFXTPointFX
TTPOLYCURVETTTPolyCurve
TTPOLYGONHEADERTPolygonHeader
ABCTABC
RASTERIZER_STATUSTRasterizer_Status
MOUSEHOOKSTRUCTTMouseHookStruct
CBTACTIVATESTRUCTTCBTActivateStruct
HARDWAREHOOKSTRUCTTHardwareHookStruct
EVENTMSGTEventMsg
WNDCLASSTWndClass
MSGTMsg
MINMAXINFOTMinMaxInfo
SEGINFOTSegInfo
ACCELTAccel
PAINTSTRUCTTPaintStruct
CREATESTRUCTTCreateStruct
CBT_CREATEWNDTCBT_CreateWnd
MEASUREITEMSTRUCTTMeasureItemStruct
DRAWITEMSTRUCTTDrawItemStruct
DELETEITEMSTRUCTTDeleteItemStruct
COMPAREITEMSTRUCTTCompareItemStruct
WINDOWPOSTWindowPos
WINDOWPLACEMENTTWindowPlacement
NCCALCSIZE_PARAMSTNCCalcSize_Params
SIZETSize
MENUITEMTEMPLATEHEADERTMenuItemTemplateHeader
MENUITEMTEMPLATETMenuItemTemplate
DCBTDCB
COMSTATTComStat
MDICREATESTRUCTTMDICreateStruct
CLIENTCREATESTRUCTTClientCreateStruct
MULTIKEYHELPTMultiKeyHelp
HELPWININFOTHelpWinInfo
CTLSTYLETCtlStyle
CTLtypeTCtltype
CTLINFOTCtlInfo
DDEADVISETDDEAdvise
DDEDATATDDEData
DDEPOKETDDEPoke
DDEAACKTDDEAck
DEVMODETDevMode
KANJISTRUCTTKanjiStruct

 

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.
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值