我在做毕业设计,调用DLL时出错,能否帮帮我,详情请看内容?(急,我的分全给你)(60分)

恰克

Unregistered / Unconfirmed
GUEST, unregistred user!
dll文件
================================================
library Project2;
{ 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,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
begin

end.
procedure showes(sender:tobject);
begin
form1.show;
end;

=================================================
dll调用文件
=================================================
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
Type TMyProc1=Procedure () ;Stdcall;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
MyHandle1:THandle;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
Var MyProc1: TMyproc1;
begin
try
MyHandle1:=LoadLibrary ('Project2.dll') ;
If MyHandle1<=0 then
Raise Exception.Create
( '动态链接库调用失败,错误代码是:'+Inttostr(Getlasterror))
else
@MyProc1:=GetProcAddress(MyHandle1,'showes(application)');
if not Assigned(MyProc1) then
Raise Exception.Create('GetProcAddress调用失败,错误代码是:'+inttostr(getlasterror))
else
begin
MyProc1();
end;
except
Freelibrary(Myhandle1);
end;
end;

end.
===================================================
出错信息
GetProcAddress调用失败,错误代码是:127
 
>/ ****
procedure showes(sender:tobject);
begin
form1.show;
//this form1do
n't create.
end;
>/ ****
 
autumn:难道还要 form1:=tform1.create(self)
 
procedure showes(sender:tobject);
没有Export出来。
 
tanglu:可以再详细点吗?谢谢!
 
在dll单元中加一段申明,
用:procedure showes(sender:tobject);export;
输出该函数。
 
Exports showes;
写在{XX}的后面
 
dll文件================================================
library Project2;
uses SysUtils, Classes,
Unit1 in 'Unit1.pas' {Form1};{$R *.RES}
exports
procedure showes(sender:tobject) index 1 name 'showes'
begin
end.

procedure showes(sender:tobject);
begin
form1.show;
end;

///////////////
Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TMyProc1=Procedure ();
type TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public { Public declarations }
end;

var
Form1: TForm1;
MyHandle1:THandle;
implementation{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
Var MyProc1: TMyproc1;
begin
try
MyHandle1:=LoadLibrary ('Project2.dll') ;
if MyHandle1<=0 then
Raise Exception.Create ( '动态链接库调用失败,错误代码是:'+Inttostr(Getlasterror))
else
MyProc1:=TMyProc1(GetProcAddress(MyHandle1,'showes'));
if not Assigned(MyProc1) then
Raise Exception.Create('GetProcAddress调用失败,错误代码是:'+inttostr(getlasterror))
else
begin
MyProc1(application);
end;
except Freelibrary(Myhandle1);
end;
end;

end.

我的delphido
wn掉啦,没有测试,应该能用。
 
不好意思,有几处错误:
TMyProc1=Procedure ();
==》 TMyProc1=Procedure(sender:tobject);
dll文件
==》
library Project2;
uses SysUtils, Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
procedure showes(sender:tobject);
begin
form1.show;
end;

exports
showes index 1 name 'showes';
begin
end.

不过,有点不明白:
你的Form1是怎么创建的?程序能运行?
 
真该死!只出去吃饭,回来就…………
我真亏!开始联不上……这么简单的问题…………
你的 FORM1 还要在使用前
Application.CreateForm(Form1,TForm1 );
一下,不然,你在DLL中,如何SHOW他?
>>jacer:“不过,有点不明白:你的Form1是怎么创建的?程序能运行?”
jacer也是半同水
应是
>>Dll
procedure showes(sender:tobject);
begin

//》》Application.CreateForm(Form1,TForm1 );
form1.show;
end;

 
library MyForms;
uses
SysUtils, Classes, Forms,
DllForm in 'DllForm.pas' {DllForm}
function ShowForm : integer;
stdcall;
var
Form: TDllForm;
begin
Form := TDllForm.Create(Application);
Result := Form.ShowModal;
Form.Free;
end;

exports
ShowForm;
begin
end;


unit TestApp;
interface

uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls;
type
Tform1 = Class(Tform)
Button1: TButton;
Procedure Button1Click(Sender: TObject);
private
{private declarations}
public
{public declarations}
end;

var
Form1: TForm1;
function ShowForm: Integer;stdcall;
external 'myforms.dll';
implementation
{$r *.dfm}
procedure Tform1.Button1Click(Sender: Tobject);
begin
showform;
end;

end.

绝对好使.
THANK YOU FOR READ MY ANSWER!!!!!!
 
干嘛都写的那么长,把改的地方说出来不就可以了
 
多人接受答案了。
 
jacer也是半同水-----》确实是这样的,不好意思 :)
to hsw:
Application.CreateForm(Form1,TForm1 );
好象不行,DLL没有默认的Application对象吧?
要怎样才能show呢?
 
我明白了。
 
顶部