首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> Delphi -> 如何将C/C++程序转译成Delphi(十二)
如何将C/C++程序转译成Delphi(十二)


文章类别:Delphi 来源: 作者: 发表日期:2006-2-4 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

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(十三)
本栏目热门文章
·Delphi工具—反编译Delphi(三) 2006-2-4
·Delphi工具—反编译Delphi(二) 2006-2-4
·Delphi工具——反编译Delphi(一) 2006-2-4
·用FASTREPORT实现WEB应用中自定义报表 2006-2-4
·Delphi中ScriptControl的高级应用(一) 2006-2-4
·利用内存映射文件扩充程序可用的内存 2006-2-4
·QQ聊天记录器演示程序 2006-2-4
·Delphi与DirectShow&DSPack/在 2006-2-4
·UltraEdit也支持Delphi语法高亮 2006-2-4
·DirectShow之接口实战篇(二) 2006-2-4
新近更新文章
·BPCS系统现金流量分析工具开发日志 2006-2-4
·程序间相互通讯问题的解决 2006-2-4
·如何获取本地HTML文件的标题,超级链接 2006-2-4
·建立自己的csdn知识管理库(1) 2006-2-4
·使用Delphi开发多媒体播放音轨问题的FAQ(原创) 2006-2-4
·监视资源管理器的文件变化 2006-2-4
·实现在virtualStringtree中编辑的标准步骤 2006-2-4
·WINDOWS编程技巧之DELPHI篇 2006-2-4
·DELPHI面向对象支持特点--保护级类成员的应用 2006-2-4
·取Run下所有值(原创) 2006-2-4
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: