请问DLL如何和主程序共享一个动态数组?或者如何读取主程序中的动态数组? ( 积分: 50 )

  • 主题发起人 主题发起人 lotuscheng2
  • 开始时间 开始时间
L

lotuscheng2

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位富翁指点一下,给个代码和Demo当感激不尽!
 
请各位富翁指点一下,给个代码和Demo当感激不尽!
 
留下 你的E_mail
 
lotuscheng@163.com
 
发了 收到回复
 
介绍一下哦
 
在主程序和DLL中都作如下定义
Type
TSYSINFORMATION = record
CZYGH,CZYXM,DLMM,DWDM,DWJB,DWMC:string

DateConnection: TSocketConnection

AppServerState:integer
//应用服务器工作状态
LoginTap:shortint;//登录标志 1:已登录
aa:array of string

b:integer

end

var SYSINFORMATION:TSYSINFORMATION

var SysInfo:^TSYSINFORMATION = @SYSINFORMATION;


然后在需要时给各项值赋值,调用时传一个pointer就可以了
调用过程:
procedure TForm_Main.CallDll(dywj:string);
type
Tcallmain=function(pt:pointer) :integer;
var
callmain:Tcallmain;
Handle: THandle;
begin
//CheckAppServerState;
if SysInfo.DLMM='000000' then
begin
Application.MessageBox('请先修改密码!','系统提示',MB_OK+MB_ICONEXCLAMATION);
N8Click(N8);
Abort;
end;

if not fileexists(dywj) then
begin
Application.MessageBox('程序调用的动态链接库文件未找到,请与软件供应商联系!','找不到相关链接文件',MB_OK+MB_ICONINFORMATION);
Abort;
end;
Handle := LoadLibrary(pchar(dywj));
try
@callmain:= GetProcAddress(Handle,'Pro_exp');
if @callmain <&gt
nil then
callmain(SysInfo)
else
Application.MessageBox('程序入口函数出错,请与软件供应商联系!','打开链接文件出错',MB_OK+MB_ICONINFORMATION);
finally
FreeLibrary(Handle);
end;
end;



DLL工程
library Pro_czygl;

{ 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,
Czygl in 'Czygl.pas' {Form_czygl},
PublicUnit in '../../pub/PublicUnit.pas' {Form_Public};

{$R *.RES}
function Pro_exp(pt:pointer):integer;
begin
SysInfo:=pt;
Application.CreateForm(TForm_czygl, Form_czygl);
Application.CreateForm(TForm_Public, Form_Public);
Form_czygl.Showmodal;
Form_Public.Close;
Form_Public.Free;
Form_czygl.Free;
result:=0;
end;

exports Pro_exp;

begin
end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部