刚刚接触Dll,不知哪 里写错了,请高手帮忙看看。万分感谢!(100分) ( 积分: 100 )

  • 主题发起人 主题发起人 雪狐狸
  • 开始时间 开始时间

雪狐狸

Unregistered / Unconfirmed
GUEST, unregistred user!
library test;
uses
SysUtils,
Classes,
Unitdll in 'Unitdll.pas' {Form1};
exports
ShowForm;
{$R *.res}
begin
end.
*************************************
unit Unitdll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowForm(AppH : THandle
DllS:TScreen;Name : pchar) : PChar
StdCall;
var
Form1: TForm1;
Username:pchar;
DllH : THandle;
AppS : TScreen;
implementation
{$R *.dfm}
function ShowForm(AppH : THandle;DllS:TScreen
Name : pchar) : PChar;
begin
DllH := Application.Handle;
AppS := Screen;
Application.Handle := AppH;
Screen :=DllS;
Form1 := TForm1.Create(nil);
Username:=Name;
try
Form1.ShowModal ;
finally
Result:=Username ;
Form1.Free;
Application.Handle := DllH;
Screen := AppS;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Edit1.text:=Username;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Username:=pchar(edit1.Text);
if (Username='0') or (ShowForm(Application.Handle,Screen,Username)='0') then form1.close;
end;
end.
 
library test;
uses
SysUtils,
Classes,
Unitdll in 'Unitdll.pas' {Form1};
exports
ShowForm;
{$R *.res}
begin
end.
*************************************
unit Unitdll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowForm(AppH : THandle
DllS:TScreen;Name : pchar) : PChar
StdCall;
var
Form1: TForm1;
Username:pchar;
DllH : THandle;
AppS : TScreen;
implementation
{$R *.dfm}
function ShowForm(AppH : THandle;DllS:TScreen
Name : pchar) : PChar;
begin
DllH := Application.Handle;
AppS := Screen;
Application.Handle := AppH;
Screen :=DllS;
Form1 := TForm1.Create(nil);
Username:=Name;
try
Form1.ShowModal ;
finally
Result:=Username ;
Form1.Free;
Application.Handle := DllH;
Screen := AppS;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Edit1.text:=Username;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Username:=pchar(edit1.Text);
if (Username='0') or (ShowForm(Application.Handle,Screen,Username)='0') then form1.close;
end;
end.
 
我是想:
DLL调用自身
直到窗体中Edit1.text='0'
 
*************************************
unit Unitdll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TScreenP = ^TScreen
// add it

type
Tf = function(Name:string):pchar
StdCall;
EDLLLoadError = class(Exception);
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
procedure Edit1DblClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowForm(Name:string):pchar
StdCall;
var
Form1: TForm1;
Username:string;
LibHandle: THandle;
main: Tf;
implementation
{$R *.dfm}

// 不要用 String 作为参数..............
function ShowForm(AppH : THandle
AppS : TScreenP
Name : PChar) : PChar;
var
DllH : THandle;
DllS : TScreen;
begin
Result := -100;
DllH := Application.Handle;
DllS := Screen;
Application.Handle := AppH;
Screen := AppS^;
Form1 := TForm1.Create(nil);
Username:=Name;
try
Form1.ShowModal ;
finally
Result :=pchar(Username);
Form1.Free;

Application.Handle := DllH;
Screen := DllS;
end;
end;
 
把你的IP改制我的IP
然后进网站买点
那样的话就是我家在买
在用你的fids导入我家的系统
我就会同意

大哥们 问下1.怎么把自己的ip改制成别人的ip?2.如何知道自己家的ip?3.什么是fids?怎样把fids导入别人家的系统?
谢谢 有知道的请告诉我
 
king198034:
你怎么在我的提问里提些不相干的东西?
 
到底发生了什么错误??
 
提示我好象指针什么的有些问题...
 
我是这样写的,参考一下吧,在D7提示不安全代码而已,不理会
begin
DLLHandle := LoadLibrary('Dll.dll');
if DLLHandle <> 0 then
begin
@CreateDllForm := GetProcAddress(DLLHandle, 'CreateDLLForm');
if Assigned(CreateDllForm) then
DLLForm := CreateDllForm(Application, Screen)
else
Exit;
end else
Exit;
end;
 
procedure TForm1.Edit1DblClick(Sender: TObject);
begin
Username:=edit1.Text;
if not (Username='0') then
begin
LibHandle := LoadLibrary('test.DLL')
// 这里...DLL自调用...应该是不可以的
try
if LibHandle = HINSTANCE_ERROR then
raise EDLLLoadError.Create('Unable to Load DLL');
@main := GetProcAddress(LibHandle, 'ShowForm');
if not (@main = nil) then
edit1.Text:=main(Username);
finally
FreeLibrary(LibHandle);
end;
end;
close;
end;
 
我就是想调用自身,调用时发现是可以的
edit1.text也能传递过去。
但我在edit1.text中输入“0”,想关闭DLL时程序却报错。
想来是我哪个地方没释放还是释放错了?
注:选择“RUN/Program Reset”结束调试时,它却说:“无法关闭,因为有其它进程存在访问...”
 
dll中最好不要使用String,用pchar
如果一定要用的话,引用sharemem单元
 
调用dll时,dll会在程序内存地址空间中保留一个副本作为程序共享访问,在以后每次调用只是增加一次引用值,你的程序中第一次调用后会产生一个form对象,之后在dll中就会共享这个实例对象以及所有相关变量值,当你输入一个不同值时只是产生了一个新的窗体实例,而原先窗体实例里面edit1的值和新窗体实例里面edit1的值及所有变量值其实完全一样了,就是因为dll共享变量的原因,访问的是相同的地址,同理,当你关闭任何一个窗体就会释放这个窗体对象和这些所有变量,当你再去关闭另外一个窗体时因为没有了这个窗体对象所以产生地址访问异常,程序流程需要改进一下
 
我赞成skyblue7080的观点,应该是地址访问异常,我在调试你程序时关闭dll窗体时的提示也是地址出错。
 
多人接受答案了。
 
后退
顶部