教我怎么在DELPHI里使用DLL呀

yagas 2003-10-18 10:41:41
教我怎么在DELPHI里使用DLL呀
...全文
52 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mib3000 2003-10-19
  • 打赏
  • 举报
回复
mark
ly_liuyang 2003-10-19
  • 打赏
  • 举报
回复
看书
简单的
proc .. stdcall; extrenal dll这样的
看Delphi的Source下很多PAS例如Windows.pas就有了

复杂的动态LoadLibrary和GetProcAddress实现
zhksoft 2003-10-19
  • 打赏
  • 举报
回复
先看书,别人一时半会不好做答的
huojiehai 2003-10-19
  • 打赏
  • 举报
回复
The main source for a dynamically loadable library is identical to that of a program, except that it begins with the reserved word library (instead of program).
Only routines that a library explicitly exports are available for importing by other libraries or programs. The following example shows a library with two exported functions, Min and Max.

library MinMax;
function Min(X, Y: Integer): Integer; stdcall;

begin
if X < Y then Min := X else Min := Y;
end;

function Max(X, Y: Integer): Integer; stdcall;

begin
if X > Y then Max := X else Max := Y;
end;

exports

Min,
Max;

begin

end.

If you want your library to be available to applications written in other languages, it抯 safest to specify stdcall in the declarations of exported functions. Other languages may not support Object Pascal抯 default register calling convention.
Libraries can be built from multiple units. In this case, the library source file is frequently reduced to a uses clause, an exports clause, and the initialization code. For example,

library Editors;
uses EdInit, EdInOut, EdFormat, EdPrint;
exports

InitEditors,
DoneEditors name Done,
InsertText name Insert,
DeleteSelection name Delete,
FormatSelection,
PrintSelection name Print,
...
SetErrorHandler;

begin

InitLibrary;
end.

You can put exports clauses in the interface or implementation section of a unit. Any library that includes such a unit in its uses clause automatically exports the routines listed the unit抯 exports clauses梬ithout the need for an exports clause of its own.
The directive local, which marks routines as unavailable for export, is platform-specific and has no effect in Windows programming.
On Linux, the local directive provides a slight performance optimization for routines that are compiled into a library but are not exported. This directive can be specified for standalone procedures and functions, but not for methods. A routine declared with local
梖or example,

function Contraband(I: Integer): Integer; local;

梔oes not refresh the EBX register and hence

cannot be exported from a library.
cannot be declared in the interface section of a unit.
cannot have its address taken or be assigned to a procedural-type variable.
if it is a pure assembler routine, cannot be called from another unit unless the caller sets up EBX.
huojiehai 2003-10-19
  • 打赏
  • 举报
回复
动态加载
uses Windows, ...; {On Linux, replace Windows with SysUtils }
type

TTimeRec = record
Second: Integer;
Minute: Integer;
Hour: Integer;
end;

TGetTime = procedure(var Time: TTimeRec);

THandle = Integer;

var

Time: TTimeRec;
Handle: THandle;
GetTime: TGetTime;
...
begin
Handle := LoadLibrary('libraryname');
if Handle <> 0 then
begin
@GetTime := GetProcAddress(Handle, 'GetTime');
if @GetTime <> nil then
begin
GetTime(Time);
with Time do
WriteLn('The time is ', Hour, ':', Minute, ':', Second);
end;
FreeLibrary(Handle);
end;

end;
yagas 2003-10-19
  • 打赏
  • 举报
回复
我没有书呀
小地方
什么都没有
softcai 2003-10-18
  • 打赏
  • 举报
回复
自己看书去
biu 2003-10-18
  • 打赏
  • 举报
回复
loadlibrary
Spacesoft 2003-10-18
  • 打赏
  • 举报
回复
晕…… 自己看书去,这样的问题怎么回答嘛……
News 26.03.2015 Knowledge base file for Delphi XE3 freely available. 23.03.2015 Knowledge base file for Delphi XE and Delphi XE2 freely available. 16.03.2015 Latest version is available for download. What is IDR? IDR (Interactive Delphi Reconstructor) – a decompiler of executable files (EXE) and dynamic libraries (DLL), written in Delphi and executed in Windows32 environment. The program firstly is intended for the companies, engaged by development of anti-virus software. It can also help programmers to recover lost source code of programs appreciably. The current version of the program can process files (GUI and console applications), compiled by Delphi compilers of versions Delphi2 – Delphi XE3. Final project goal is development of the program capable to restore the most part of initial Delphi source codes from the compiled file but IDR, as well as others Delphi decompilers, cannot do it yet. Nevertheless, IDR is in a status considerably to facilitate such process. In comparison with other well known Delphi decompilers the result of IDR analysis has the greatest completeness and reliability. Moreover interactivity does work with the program comfortable and (we shall not be afraid of this word) pleasant. IDR make static analysis (analyzed file is not loaded to memory and executed) that allows to safely investigate viruses, trojans and other malware applications, those which executing is dangerous or is not desirable. The program does not require any installation activity and does not do any records in Windows registry. Below screenshot of IDR main window is shown. You can find examples of IDR working results on separate page. For detailed acquaintance with opportunities IDR there is a help file in format CHM which can be downloaded on page of download or directly from this link.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧