e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 程序开发 >> PowerBuilder教程 >> 如何用VC创建可在PB中调用的DLL >> 教程正文
 
教程搜索
 
 
相关教程
  • 在PowerBuilder中利用Dat
  • 什么是“pbcat表?
  • 修改PB6的PBL,使之在PB5中
  • 使用日期格式时的一些问题
  • 如何存取二进制大对象(BL
  • 关于PowerBuilder的补丁包
  • 如果在isql中建立表或者增
  • PB高级开发环境配置
  • 动态设置Win95和NT的缺省
  • PowerBuilder6.0运行环境
  • PowerBuilder、InfoMaker
  • PB API调用原型
  • 如何用VC创建可在PB中调用
  • PB应用技巧——数据窗口自
  • 为PB加入具有布局功能的容
  • PB7.0通用选字段查询窗口
 
 
赞 助 商
 
 
如何用VC创建可在PB中调用的DLL
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9

DLLs: An Overview

A dynamic-link library (DLL) is an executable file that acts as a shared library of functions. Dynamic linking provides a way for a process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which contains one or more functions that are compiled, linked, and stored separately from the processes that use them. DLLs also facilitate the sharing of data and resources. Multiple applications can simultaneously access the contents of a single copy of a DLL in memory. This code can be called from a PowerBuilder program even though it is written in another language such as C/C++, Pascal or in any other language that supports the pascal, WINAPI macro calling sequence for 16-bit and the standard calling sequence for 32-bit.

Dynamic linking differs from static linking in that it allows an executable module (either a .DLL or .EXE file) to include only the information needed at run time to locate the executable code for a DLL function. In static linking, the linker gets all the referenced functions from the static link library and places it with your code into your executable. Using DLLs instead of static link libraries makes the size of the executable file smaller. If several applications use the same DLL, this can be a big savings in disk space and memory.

A .DLL file has a layout very similar to an .EXE file, with one important difference - a DLL file contains an exports table. The exports table contains the name of every function that the DLL exports to other executables. These functions are the entry points into the DLL; only the functions in the exports table can be accessed by other executables. Any other functions in the DLL are private to the DLL.


You can export functions from a DLL with two methods:

1) Create a module definition (.DEF) file and use the .DEF file when building the DLL.

2) Use the keyword __declspec(dllexport) in the function's definition. When exporting functions with either method, make sure to use the __stdcall calling convention.

The __stdcall calling convention is used to call Win32 API functions.

__stdcall pushes parameters on the stack, in reverse order (right to left)

Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

Element Implementation

Argument-passing order Right to left.

Argument-passing convention By value, unless a pointer or

reference type is passed.

Stack-maintenance responsibility Called function pops its own

arguments from the stack.

Name-decoration convention An underscore (_) is prefixed to the

name. The name is followed by the at

sign (@) followed by the number of

bytes (in decimal) in the argument list.

Therefore, the function declared as

int func( int a, double b ) is decorated

as follows: _func@12

Case-translation convention None

Example

In the following example, use of __stdcall results in all WINAPI function types being handled as a standard call:

// Example of the __stdcall keyword


#define WINAPI __stdcall

Export from a DLL Using .DEF Files

The most common methods for exporting a definition:

1.The __declspec(dllexport) keyword in the source code

2.An EXPORTS statement in a .DEF file

You can export data, functions, classes, or class member functions from a DLL by using the __declspec(dllexport) keyword. If you use __declspec(dllexport), you do not need a .DEF file for exports.

To export functions, the __declspec(dllexport) keyword must appear to the left of the calling-convention keyword, if a keyword is specified. For example:

void __declspec(dllexport) __cdecl Function1(void);

To export all the public data members and member functions in a class, the keyword must appear to the left of the class name as follows:

class __declspec(dllexport) CExampleExport : public CObject

{ ... class definition ... };

When building your DLL, you typically create a header file that contains the function prototypes and/or classes you are exporting, and add the __declspec(dllexport) to the declarations in the header file. To make your code more readable, define a macro for __declspec(dllexport) and then use the macro with each symbol you are exporting:

#define DllExport __declspec( dllexport )

Pros and Cons of Using __declspec(dllexport)

Using __declspec(dllexport) is convenient because you do not have to worry about maintaining a .DEF

[1] [2] [3] [4] 下一页

  • 上一篇教程: PB应用技巧——数据窗口自动折行
  • 下一篇教程: PB API调用原型
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.