请问delphi怎么生成dll文件啊

erbiezi0000 2006-12-01 09:34:08
我对动态链接库不大熟悉,希望大家能讲的具体点,谢谢!
 我在delphi建立了一个project,里面自己编写了一个类,类有相关的私有变量和公有函数,保存文件名为UCoord.pas.
请问我怎么把我自己编写的类生成dll呢.然后怎么调用呢?
...全文
452 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangshud 2006-12-01
  • 打赏
  • 举报
回复
File->New->Other->Dll Wizard新建一个以Library开头的工程文件

library HkTest;

uses
UCoord in UCoord.pas';//把你的UCoord.pas加入工程

exports//输出部分
EnableHotKeyHook,//供外面调用的函数

begin

end.

你的UCoord.pas单元
unit HKKeyProc;

interface

uses
windows, Messages;

var
hnextHookProc: HHook;
ProcSaveExit: Pointer;
//你的function GetParams(): TstringList
function KeyBoardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LParam): lresult;stdcall; export;

function EnableHotKeyHook: Bool; export;
function DisableHotKeyHook: Bool; export;
procedure HotKeyHookExit; far;

implementation

function KeyboardHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT
stdcall; export;
const
_KeyPressMask = $80000000; //按键代码
begin //开始一个循环的钩子
Result := 0;

if iCode < 0 then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;

// 监测 Ctrl + C 组合热键
if ((lParam and _KeyPressMask) = 0) and (GetKeyState(vk_Control) < 0) and (wParam = Ord('C')) then
begin
Result := 1;
WinExec('c:\windows\calc.exe', sw_Normal); //运行计算器程序
end;
end;

function EnableHotKeyHook: BOOL; export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
// 挂上钩子并保留返回值形成钩子环(Hook Loop)
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD, KeyboardHookHandler, HInstance, 0);
Result := hNextHookProc <> 0;
end;

function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc); // 解除键盘钩子
hNextHookProc := 0;
MessageBeep(0); //扬声器鸣叫提示
end;
Result := hNextHookProc = 0;
end;

procedure HotKeyHookExit;
begin
//即使忘了解除 HOOK,自动解除
if hNextHookProc <> 0 then DisableHotKeyHook;
ExitProc := procSaveExit;
end;

end.
最后Project-->Build 你的工程名称
编译工程就生成Dll.
yousite1 2006-12-01
  • 打赏
  • 举报
回复
file -> new -> other ->Active X Library
在uses後裏寫函數然後

exports
showAbout,calc_x2; //相應的要對外發布的函數名。

例如:
library dll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes,
Forms,
About in 'About.pas' {frmAbout};

procedure showAbout(title:shortString);stdcall;
var frmAbout:TfrmAbout;
begin
frmAbout:=TfrmAbout.Create(Application);
frmAbout.Caption:=title;
frmAbout.ShowModal;
frmAbout.Release;
end;
function calc_x2(i:integer):integer;stdcall;
begin
result:=i*i;
end;
{$R *.res}
exports
showAbout,calc_x2;
begin
end.
erbiezi0000 2006-12-01
  • 打赏
  • 举报
回复
例如我自己写了一个UCoord.pas文件,里面定义了一个类,如下:
type
THHUCoord = class
private
C_LT_L: double;
public
function GetParams(): TstringList;
end;
怎么把它生成dll文件,供其它文件调用呢?
jiangshud 2006-12-01
  • 打赏
  • 举报
回复
你该不会是问如何生成DLL吧.
cangwu_lee 2006-12-01
  • 打赏
  • 举报
回复
关键是这两种 .DLL 是截然不同的做法。



例如,其中一个做法:

function My函数():int; STDCALL;
var MyClass:TMyClass;
begin
MyClass:=TMyClass.create();

//do some thing

MyClass.Free();
end;


Exports
My函数;

erbiezi0000 2006-12-01
  • 打赏
  • 举报
回复
晕 这也算回帖啊 我就是没有书才发帖子的
我在网上看了很多资料 生成dll很简单 就是在函数后面加几个字
但是怎么定义成类的样子呢   
还能给点提示
hydonlee 2006-12-01
  • 打赏
  • 举报
回复

唉。。。真不知道是应该不应该讲给你。。。不讲吧,你不会。 

讲了吧,这是磨灭你自学的积极性。。。

这个问题不难,我还是不讲了吧。 你随便找本书看看吧。。。

要学会学习,我坚持一点:授人于鱼不如授人于渔。
erbiezi0000 2006-12-01
  • 打赏
  • 举报
回复
我现在是自己编写了一个类,想把它生成dll文件就行,请问怎么实现
cangwu_lee 2006-12-01
  • 打赏
  • 举报
回复
你是想做成 ActiveX DLL 还是普通的 Windows DLl
erbiezi0000 2006-12-01
  • 打赏
  • 举报
回复
还能写的具体点啊 我现在定义的类怎么封装生成dll啊
cangwu_lee 2006-12-01
  • 打赏
  • 举报
回复
函数加上 STDCALL;
然后 Exports

5,930

社区成员

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

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