DLL静态调用没问题,动态调用退出时死机(第一次遇到这个问题)(50分)

  • 主题发起人 主题发起人 hying95
  • 开始时间 开始时间
H

hying95

Unregistered / Unconfirmed
GUEST, unregistred user!
var
FrmAuto_GS: TFrmAuto_GS;
DM_PF: TDM_PF;
function Show_Auto_GS(aHandle:THandle; aString:string;isDX:
Boolean):Boolean;stdcall;

implementation
uses MyFun, Lunar;
{$R *.dfm}

function Show_Auto_GS(aHandle:THandle; aString:string;isDX: Boolean):Boolean;stdcall;
var
sLis: TStrings;
begin
sLis:=TStringList.Create;
sLis.Text:=StringReplace(aString, ',', #13#10, [rfReplaceAll] );
Application.Handle:=aHandle;
DM_PF:=TDM_PF.Create(Application);
FrmAuto_GS:=TFrmAuto_GS.Create(Application);
try
if sLis.Count=4 then
begin
FrmAuto_GS.Caption:=sLis.Strings[0];
FrmAuto_GS.ComboBox1.Text:=sLis.Strings[2];
FrmAuto_GS.cbCS.Text:=sLis.Strings[1];
FrmAuto_GS.ListBox2.Items.Add(sLis.Strings[3]);
end Else
if sLis.Count=1 then FrmAuto_GS.Caption:=sLis.Strings[0];

if isDX then
FrmAuto_GS.ChBox.Checked:=True else FrmAuto_GS.ChBox.Checked:=False;
FrmAuto_GS.bsBusinessSkinForm1.SkinData:=DM_PF.bsSkinData1;

FrmAuto_GS.ShowModal;
result:=False;
finally
FrmAuto_GS.Free;
end;
sLis.Free;
end;

library GS_32;

uses
ShareMem,
SysUtils,
StrUtils,
Classes,
Lunar in 'Lunar.pas',
MyFun in 'MyFun.pas',
MyIni in 'MyIni.pas',
UAuto_GS in 'UAuto_GS.pas' {FrmAuto_GS},
UOpen in 'UOpen.pas' {FrmOpen},
USkin_PF in 'USkin_PF.pas' {DM_PF: TDataModule};

{$R *.res}

exports
Show_Auto_GS;
begin
end.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

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

var
Form1: TForm1;
//Function Show_Auto_GS(aHandle:THandle; aString:string;isDX:
// Boolean):Boolean;stdcall;external 'GS_32.dll';
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
dllName,FuncName:string;
LibHandle:HWND;
DName:Function(aHandle:THandle; aString:string;isDX:
Boolean):Boolean;stdcall;
begin
dllName:='GS_32.dll';
FuncName:='Show_Auto_GS';
S:=Application.Title;

LibHandle:=LoadLibrary(pchar(dllName));
if LibHandle<32 then
begin
MessageBox(0,pchar('Not Found'+ dllName),'Error',0);
Exit;
end;
@DName:=GetProcAddress(LibHandle,pchar(FuncName));
if @DName=NIL then
begin
MessageBox(0,pchar('Not Found '+FuncName+' in'+ dllName),'Error',0);
FreeLibrary(LibHandle);
Exit;
end;
try
DName(Application.Handle,S,true);
finally
FreeLibrary(LibHandle);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
//把下面静态调用和前面静态引用注释后,退出死机,
//Show_Auto_GS(Application.Handle,application.Title,true);
end;

end.
 
后退
顶部