国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

如何將C/C++程序轉譯成Delphi(十二)

2019-11-18 18:50:07
字體:
來源:轉載
供稿:網友

5. Conditionals

###ToDo


Back to contents

6. Functions

6.1. Basics

Let's use the following C-declaration as an example of declaring a function:

WINADVAPIBOOLWINAPIControlService(    SC_HANDLE           hService,    DWord               dwControl,    LPSERVICE_STATUS    lpServiceStatus    );

[Options] ReturnValueType [Options] FunctionName ( [ParameterList] )

ReturnValueType:Specifies the type of the return value of the function. In the example above the type of the return value is BOOL. If the function does not return a value the keyword VOID is used and the translation in Delphi is a PRocedure. Please note, that the type identifier can also be "hidden" in an identifier defined using #define.
Options:Options can be a token specifying the calling convention and/or other keywords telling the compiler how to handle the function in question. The most important item is the calling convention. In the Windows-API header files, the calling convention is usually "hidden" in an identifier declared using #define, so you have to look what is defined. The example above uses the WINAPI symbol which is declared as __stdcall. This is necessary for the translation, too. Every Options item must be assessed for impact and discarded or implemented.
FunctionName:Specifies the name of the function
ParameterList:List of parameters passed to the function separated with ",". Parameters are declared via a type identifier or via a type identifier + parameter name combination.


Back to contents

6.2. Calling Conventions

Referring to the example:

WINADVAPIBOOLWINAPIControlService(    SC_HANDLE           hService,    DWORD               dwControl,    LPSERVICE_STATUS    lpServiceStatus    );

The type of the return value is BOOL. Now let's have a look at the definition of WINAPI. WINAPI is defined in windef.h the following way:

#define WINAPI __stdcall

The __stdcall keyword tells the C-compiler to use the standard-call calling convention for the function, so we have to declare the function using stdcall, too, since the default calling convention is Register in Delphi.

The function accepts three parameters. The first is a parameter with type SC_HANDLE, the second is a DWORD and the third is a pointer to a PServiceStatus structure.

Here is a Delphi translation of the example above:

Function ControlService (hService: SC_Handle;                         dwControl: DWORD;                         lpServiceStatus: PServiceStatus): Bool; stdcall;

Notes:

  1. SC_Handle is defined in WinSvc.pas.
  2. The C variable hService appears to conflict somewhat with the Delphi convention that employs H as the initial letter for a handle type. Whilst it seems desirable to use an alternative (hndService:HControlService, for example), Delphi will accept duplicate names in a parameter list (e.g. hwnd: HWND). Since Borland does it and it works, I would recommend staying with that convention.

Let's have a look at another function declaration:

ULONG (FAR PASCAL MAPISENDDOCUMENTS)(    ULONG ulUiparam,    LPSTR lpszDelimChar,    LPSTR lpszFilePaths,    LPSTR lpszFileNames,    ULONG ulReserved);

Well, this declaration contains a trap. The keyword PASCAL has been used to specify the Pascal-calling convention, which was usually used in the 16bit-Windows. But not under Win32. Look at the following line in the windef.h file:

#define PASCAL __stdcall

The windef.h header declares PASCAL as __stdcall, which specifes the stdcall calling convention, so you have to use stdcall calling convention in this case, too.

Notes

  1. It is very important to trace through all the #include files for any #defines which may affect the translation.
  2. The FAR keyword can be ignored in Delphi.


Back to contents


上一篇:如何將C/C++程序轉譯成Delphi(十三)

下一篇:如何將C/C++程序轉譯成Delphi(十一)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 安陆市| 周口市| 汉阴县| 凤冈县| 十堰市| 黄陵县| 富源县| 比如县| 萨嘎县| 库车县| 武宁县| 广东省| 大余县| 清徐县| 营口市| 灵武市| 新丰县| 克山县| 佛教| 阿拉善盟| 五家渠市| 商都县| 正阳县| 惠来县| 旬阳县| 班戈县| 广元市| 白城市| 改则县| 咸阳市| 广平县| 图片| 贺兰县| 鹤山市| 石林| 龙陵县| 手游| 望江县| 拉孜县| 通渭县| 双城市|