关于dll显式调用的一个问题.急!急!急!急!急!急!急!急!急!(100分)

  • 主题发起人 wind1278wind
  • 开始时间
W

wind1278wind

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个主程序来调用dll中的子程序.(主界面要调用9个dll方式的子程序).可是每当我用
freeLibrary卸载dll的时候.主程序就不见了.请问各位高手这是怎么一会事情.如果我不卸载
它就会在运行一段时间死机
我得调用方式如下:.
Th:=LoadLibrary('Yzyw.dll');
if Th>0 then
try
@TIntFunc:=GetProcAddress(Th,PChar('ShowForm'));
if Assigned(TIntFunc) then begin
uRet:=TIntFunc(Application.Handle,IsCardIn);
end
else
ShowMessage('ShowForm函数没有找到');
Except
FreeLibrary(Th);
end
卸载放在下一次调用之前.
freelibrary(th);
Th:=0;

dll中:
function ShowForm(AHandle:THandle;ACaption:String):LongInt;stdcall;
begin
Application.Handle :=AHandle;
if ACaption='InCard' then
begin
if Not Assigned(FrmInCard) then
FrmInCard:=TFrmInCard.Create(Application);
try
Result:=LongInt(FrmInCard);
FrmInCard.Show;
Except
Result:=-1;
end;
end;
end;
请各位高手帮忙解决一下.很急!!!!!!!!!!!!!!!!!!!!!!
 
Note: When writing a DLL that uses VCL forms, assign the window handle of the host EXE's main window to the DLL's Application.Handle property. . This makes the DLL's form part of the host application.
帮助中说将主窗口的handle给dll的application.handle, 可没说把exe的application.handle给dll的application.handle啊.
也许错误就在这里了。
 
Pearl你好:
你的建议好像可以,我正在测试中.如果采纳马上送分.
 
Pearl你好:
使用你的方法.闪动的问题是解决了.但是在Dll中不能响应回车事件.是程序无法运行.
请问有没有解决方法.或者更好的解决闪动的方法.

 
很简单呀。
就是不要指定dll中application.handle。
 
不传application.handle会不会出现其他的问题.这样动态库岂不是和主程序独立起
来了吗?会不会出现其他问题?
 
一般不会。 我一直这样用的。 而且用得很好。
 
这样做就会成为两个程序,而且可以互相切换.如果程序运行中主程序跳出来怎么办.
我得程序主程序是不能随便出来的,只有动态库里面处理完了,主程序才能出来.
 
Pearl你在线吗?能不能留下你的qq号码,或者电话号码..我这个问题很急.必须赶快解决.
 
uRet:=TIntFunc(Application.Handle,IsCardIn);这句话中不要使用Application.Handle
试试使用当前窗体的Handle看看.
 
uRet:=TIntFunc(Handle,IsCardIn) 这样动态库里面不响应enter,up,down键,我必须
用到这些键怎么办...有好的办法吗...我得qq号:26687358我们直接聊.
 
unit Unit1;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;

type
TShowAbout = procedure(AHandle: THandle; ACaption: string; AName: string); StdCall;

EDLLLoadError = class(Exception);


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

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle: THandle;
ShowAbout: TShowAbout;
begin
LibHandle := LoadLibrary('Aboutdll.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('不能装载动态链接库,请确认动态链接库的存在!');
@ShowAbout := GetProcAddress(LibHandle, 'ShowAboutFrm');
if not (@ShowAbout = nil) then
ShowAbout(Form1.Handle, 'About...','飘摇客通讯录')
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;

end.
 
dll中form显示用showmodal呀。 只有关闭dll的form才能返回exe。如果要屏幕上没有主程序的form只要在调dll前主form.visible:=false, 调用完成后再visible := true就可以了嘛(我就是这么做的)。
 
pearl,飘摇客:
我的问题到目前为止已经基本解决了.谢谢你们的帮忙.
方法:
把Application.Handle换成Handle问题解决.
 
to wind1278wind : 可否给我一份代码看看,谢谢。
yt_wyb@163.net
 
顶部