很菜的问题。怎样象dll文件传递数值。在线等待中

xzhongjin 2002-06-18 05:57:28
小弟初学,不知道怎样向一个dll传递要执行的数值。问题解决马上给分
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoweicaisd 2002-06-19
  • 打赏
  • 举报
回复
调用
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
ADOConnection1: TADOConnection;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure DoTest(H: THandle; { 传递句柄 }
AConn: TADOConnection; { 传递数据库连接 }
S: string; { 传递文本信息 }
N: Integer); { 传递数值信息 }
cdecl; { 指定调用协议 }
external 'Project2.dll'; { 指定过程来源 }

{ 调用过程 }

procedure TForm1.Button1Click(Sender: TObject);
begin
DoTest(Application.Handle,
ADOConnection1,
'Call OK',
256);
end;

end.
luoweicaisd 2002-06-19
  • 打赏
  • 举报
回复
dll文件


library Project3;

{ 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,
Unit2 in 'Unit2.pas' {Form1};

{$R *.res}
exports
showform,
closeform;
// DoTest;
begin

end.


unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm2 = class(TForm)
ADOConnection1: TADOConnection;
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;

procedure DoTest(H: THandle; { 获得调用者的句柄 }
AConn: TADOConnection; { 获得调用者的数据库连接 }
S: string; { 获得一些文本信息 }
N: Integer); { 获得一些数值信息 }
cdecl; { 指定调用协议 }
function showform(Ahandle: Thandle; Acaption: string): longint; stdcall;

procedure closeform(Aformref: longint); stdcall;

implementation

{$R *.DFM}

procedure DoTest(H: THandle; AConn: TADOConnection; S: string; N: Integer);
begin
Application.Handle := H; { 将过程的句柄赋值为调用者的句柄 }
{ 上面语句的作用在于, DLL的句柄和调用者的句柄相同,在任务栏中就不会 }
{ 各自出现一个任务标题了。 }
with TForm2.Create(Application) do
try { 创建窗体 }
Memo1.Lines.Append('成功调用'); { 显示一行信息 }
ADOConnection1 := AConn; { 获得数据库连接的实例 }
Memo1.Lines.Append(
ADOConnection1.ConnectionString +
' - ' + S + ' - ' + IntToStr(N)); { 根据得到的参数显示另一行信息 }
ShowModal; { 模式化显示窗体 }
finally
Free; { 调用结束时销毁窗口 }
end;
end;

function showform(AHandle: THandle; Acaption: string): longint;
var
form2: Tform2;
begin
showmessage('0');
Application.Handle := AHandle;
showmessage('1');
form2 := Tform2.Create(application);
showmessage('2');
result := longint(form2);
showmessage('3');
form2.Caption := Acaption;
form2.Show;

end;

procedure closeform(Aformref: longint);
begin
if Aformref > 0 then
Tform2(Aformref).Free;
end;
end.
freekany2002 2002-06-18
  • 打赏
  • 举报
回复
这样:
FUNC(P1:INTEGER。。。。VAR PN:PCHAR):BOOLEAN;STDCALL;
xzhongjin 2002-06-18
  • 打赏
  • 举报
回复
最好有代码表示

5,388

社区成员

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

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