执行程序部分:
TCard_RW = function(App: TApplication; AValue: Pdouble; AName,
ALocal: PChar; AMaxValue: Double; ResultChar: PChar): integer; stdcall;procedure TForm1.Button1Click(Sender: TObject);
var Dllpath: string;
Moudle: THandle;
Pfunc: TCard_RW;
Aint:Double;
PA:PChar;
SAveApp:TApplication;
begin
Dllpath := 'D:\work\test_Interface.dll';
aint:=1243.45;
SAveApp:=Application; Moudle := Loadlibrary(PChar(dllPath));
GetMem(PA,255);
try
if Moudle <> 0 then
begin
@Pfunc := GetProcAddress(Moudle, 'Card_RW');
if @Pfunc <> nil then
begin
ADOConnection1.Open(); Pfunc(Application,@Aint,'admin','001',5000,PA);
ADOConnection1.Close;
end;
end;
finally
// Application:=SAveApp; FreeMem(PA);
Freelibrary(Moudle);
end;end;动态库 部分:function Card_RW(App: TApplication; AValue: Pdouble; AName, ALocal: PChar; AMaxValue: Double; ResultChar: PChar): integer; stdcall;
var Form: TConSumeForm;
Aint: Double;
Astr: string;
var OraApp: TApplication;
begin
Result := 1;
OraApp := App;
Application := App; coinitialize(nil); DllPath := PChar(ExtractFilePath(Application.ExeName) + 'test_Interface'); Card_DataM := TCard_DataM.Create(nil);
try
with Card_DataM do
begin if not ConnectToServer then Exit;
if not LoadMsg then Exit; form := TConSumeForm.Create;
try
with form do
begin
SMaxValue := AMaxValue;
LoadName := 'FrontFormDisp_Interface';
Con_Value.Value := avalue^;
if ShowModal = mrok then
begin
Astr := '卡号:' + sid.Text + ' 姓名:' + c_name.Text + ' 卡内余额:' + floattostr(SValue.Value - con_value.Value) +
' 有效期:' + ENDDATE.Text;
StrCopy(ResultChar, PChar(Astr));
aint := con_value.Value;
AValue := @aint;
Result := 0; end else Result := 1;
end;
finally
FreeAndNil(Form);
end;
end; finally
counInitialize;
FreeAndNil(Card_DataM); end;end;现象:执行测试程序通过动态库生成一个窗口,关闭这个窗口后,测试程序原来的窗口消失,请教如后解决
TCard_RW = function(App: TApplication; AValue: Pdouble; AName,
ALocal: PChar; AMaxValue: Double; ResultChar: PChar): integer; stdcall;procedure TForm1.Button1Click(Sender: TObject);
var Dllpath: string;
Moudle: THandle;
Pfunc: TCard_RW;
Aint:Double;
PA:PChar;
SAveApp:TApplication;
begin
Dllpath := 'D:\work\test_Interface.dll';
aint:=1243.45;
SAveApp:=Application; Moudle := Loadlibrary(PChar(dllPath));
GetMem(PA,255);
try
if Moudle <> 0 then
begin
@Pfunc := GetProcAddress(Moudle, 'Card_RW');
if @Pfunc <> nil then
begin
ADOConnection1.Open(); Pfunc(Application,@Aint,'admin','001',5000,PA);
ADOConnection1.Close;
end;
end;
finally
// Application:=SAveApp; FreeMem(PA);
Freelibrary(Moudle);
end;end;动态库 部分:function Card_RW(App: TApplication; AValue: Pdouble; AName, ALocal: PChar; AMaxValue: Double; ResultChar: PChar): integer; stdcall;
var Form: TConSumeForm;
Aint: Double;
Astr: string;
var OraApp: TApplication;
begin
Result := 1;
OraApp := App;
Application := App; coinitialize(nil); DllPath := PChar(ExtractFilePath(Application.ExeName) + 'test_Interface'); Card_DataM := TCard_DataM.Create(nil);
try
with Card_DataM do
begin if not ConnectToServer then Exit;
if not LoadMsg then Exit; form := TConSumeForm.Create;
try
with form do
begin
SMaxValue := AMaxValue;
LoadName := 'FrontFormDisp_Interface';
Con_Value.Value := avalue^;
if ShowModal = mrok then
begin
Astr := '卡号:' + sid.Text + ' 姓名:' + c_name.Text + ' 卡内余额:' + floattostr(SValue.Value - con_value.Value) +
' 有效期:' + ENDDATE.Text;
StrCopy(ResultChar, PChar(Astr));
aint := con_value.Value;
AValue := @aint;
Result := 0; end else Result := 1;
end;
finally
FreeAndNil(Form);
end;
end; finally
counInitialize;
FreeAndNil(Card_DataM); end;end;现象:执行测试程序通过动态库生成一个窗口,关闭这个窗口后,测试程序原来的窗口消失,请教如后解决
解决方案 »
- DefaultHandler可以用来拦截消息?
- ■■■VBS脚本能否执行API函数?如何用?
- DLL是运行生成还是编译生成?引用动态库用stdcall;far;external调用是什么意思?一般只用external啊
- 如何在一个窗体中运行外部程序?
- 关于winsock数据提取
- 求助:如何获得屏幕上给定坐标点的十六进制颜色值???
- 初学编程的问题!!!
- 可以提供Delphi6的SN文件吗?
- 超级难题,关于资源文件的,高手请进
- 请问paradox中用如何获取当前日期?
- 昨天比晚不算,那是周六,明天就是星期一,今天再比!~~~嘿嘿~~~
- 为什么我的程序里定义了一个双精度型的字段,在DBGRID里就不能输入小数了呢 ?
要么把这句
application := app去掉
要么是在函数返回前用
application := nil;
不要让dll动链库自动释放这个指针所指向的对象可能也有其它的办法,嘿嘿,我就不会了
ALocal: PChar; AMaxValue: Double; ResultChar: PChar): integer; stdcall;
exe调用: Card_RW(Application.Handle,....);或者(Application.MainForm.Handle,....);
dll部分:Application.Handle := AppHandle;
DllPath := PChar(ExtractFilePath(ParamStr(0)) + 'test_Interface'); Card_DataM := TCard_DataM.Create(Application);
try
finally
Card_DataM.Free;
end;