关于Dll的问题,还是Delphi的问题?(100分)

  • 主题发起人 主题发起人 太阳河上
  • 开始时间 开始时间

太阳河上

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手:
这是我编写的Dll调用程序,但在调用时有总是出现:
第一个错误窗口:
应用程序发生异常未知的软件 异常(0x0eedfade),位置为0x77e69b01
第二个错误窗口:
"0x005c3a3e"指令引用的"0x0155c014"内存。该内存不能为"read"
我调用的如下:
1。做好了一个Xjgl的项目文件,主界面是XjglMainForm,现要把Xjgl做成Dll文件,给其它
调用。
2。生成Dll文件过程
library Xjgl;

{ 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,
ActiveX,
XjglExport in 'XjglExport.pas';

{$R *.res}

begin
CoInitialize(nil);
end.

unit XjglExport;

interface
uses Windows, Messages,XjglMain,Forms;

procedure CreateXjgl(Appt: THandle;User,Pass: String); stdcall;

exports
CreateXjgl Index 1 Name 'CreateXjgl' Resident;
implementation

procedure CreateXjgl(Appt: THandle;User,Pass: String);
begin
Application.Handle:=Appt;
try
XjglMainForm:=TXjglMainForm.Create(Application);
XjglMainForm.puUser:=User;
XjglMainForm.puPass:=Pass;
XjglMainForm.ShowModal;
if XjglMainForm<>nil then
begin
//Application.MessageBox('Free!','提示',mb_ok);
XjglMainForm.Free;
XjglMainForm:=nil;
end;
except
//XjglMainForm.Free;
Application.MessageBox('无法创建实例!','提示',mb_ok);
end;
end;
end.
3.调用Dll文件过程
unit JwglMain;

interface

implementation
uses DllUnit,Fnuc,JwglData;
{$R *.dfm}



procedure TJwglMainForm.HemisphereButton1Click(Sender: TObject);
begin
//Application.Terminate;
Close;
end;

procedure TJwglMainForm.GrapLabel1Click(Sender: TObject);
var FPro: TFarProc;
Moudle: THandle;
Path: String;
begin
try
with JwglDM.Client10 do
begin
Close;
CommandText:='SELECT * FROM Xjglyhb WHERE (Jsdm='+QuotedStr(Edit1.Text)+
') AND (Qx4='+QuotedStr(Edit2.Text)+')';
Open;
if RecordCount>0 then
CreateXjgl(Application.Handle,Edit1.Text,Edit2.Text)
else Application.MessageBox('没有权限进入本系统!','提示',mb_ok);
end;
except
end;
end;


end.

unit DllUnit;

interface
procedure CreateXjgl(Appt: THandle;User,pass: String); Stdcall;
procedure CreateJxjhgl(Appt: THandle;User,pass: String); Stdcall;

implementation
Procedure CreateXjgl(Appt: THandle;User,pass: String);far; External 'Xjgl.dll' name 'CreateXjgl';
Procedure CreateJxjhgl(Appt: THandle;User,pass: String);far; External 'Jxjhgl.dll' name 'CreateJxjhgl';

end.
哪位高手指点一下?
 
1:
Procedure CreateXjgl(Appt: THandle;User,pass: String);
這個過程的參蘇string改為pchar看看
 
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
 
问题是当退出JwglMain时才有问题
语句都一样
 
有个ShareMemRep.pas 的文件可以省掉动态链接库

aimingoo (周爱民) 提供的一个 ShareMem 的替代品
可以解决动态链接库使用Delphi字符串作为过程参数的问题
 
老声长谈的问题了

在dll和项目文件的uses的第一个位置处加上sharemem
但是发布的时候要加上BORLANDMM.DLL
 
按我上面说的,就不用带BORLANDMM.DLL 了
 
同意lich,
aimingoo (周爱民)的这个东东是个好东东,我就用它
 

ShareMemRep.pas如何使用?

在哪找aimingoo文件?又如何使用?
准备分配分数!不好意思分数太少,各位好。
 
在写书的时候,突发奇想地写下了这个单元。

感谢FastShareMem及其作者Emil Santos(ems@codexterity.com),是他的这个项目启发了我的思路。

在近一年前,我修改过FastShareMem的早期版本(1.01),并联系Emil Santos,由他发布了改后的FastShareMem v1.2。正是由于这次修改,使我对Delphi的ShareMem有了重新的认识,也是因此才会有ShareMemRep。

ShareMemRep与FastShareMem的共同之处在于“在DLL中使用EXE的内存管理器,而无需另外编写内存管理器的代码”。只不过两者实现的机制不同。


使用ShareMemRep,可以彻底地抛开BORLNDMM.DLL和ShareMem.pas单元。你无需再关心ShareMem的细节,因为DLL与EXE使用了同一个内存管理器。由此带来的另一个好处是:你可以随意替换EXE中的内存管理器,而无需更改DLL中的任何代码。:)


History:
=========================
2003.09.13 22:42:40
------------------
Ver1.5 :
- more and more change...

2003.08.12
------------------
Ver1.4, only for MySelf. ^,^

2003.08.08 03:52:55
------------------
Ver1.3, thank rain(czy79@hotmail.com) to report some bugs. New :
- fix some bug
- Full support Exception and Static DLL
- Rewrite Frameset
- now, kick psapi.dll(in Ver1.2, need this module), hehe...
- more and more sample and test project...

2003.08.07 04:42:54
------------------
Ver1.2 :
- Support Multi Thread. Replace old DllProc.
- now, you can use third MemMgr in your Static DLL Module, It's Safe.
- detail note in source.
- more samples...

2003.08.05 11:27:00
------------------
Ver 1.1, Hehe...Enhance, and full function for ShareMem.pas.
Some tiny bug fix.

2003.08.05 2:00:02
------------------
Ver 1.0, and test project complete! ^,^


http://aiming.ynxx.com/ShareMemRep.htm
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2084058
 
如何使用呀?
象ShareMem一样吗?放在Use后即可?
 
当然,必须是应用程序的第一个引用单元
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
628
import
I
I
回复
0
查看
647
import
I
S
回复
0
查看
677
SUNSTONE的Delphi笔记
S
后退
顶部