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++ 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.
 
 

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

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

05-07 15:08
查看更多