接口定义单元:。。
unit uInterMain;interfacetype
IMan=interface(IInterface)
['{F6F1A26D-7A7D-427D-820D-09B0B2F71407}']
procedure hello;end;implementationend.接口实现单元:
unit uOprMain;interfaceuses
uInterMain,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Activex, ScktComp,uDataMain;type
TMan=class(TInterfacedObject,IMan) public
procedure hello;
constructor create;
end;implementation constructor TMan.create;
begin
inherited create;
end; procedure TMan.hello;
begin
showmessage('asdf');
end;end.
dll单元。
library pDllMain;
uses
SysUtils,
Classes,
uInterMain in 'uInterMain.pas',
uOprMain in 'uOprMain.pas';{$R *.res}
function createMan:IMan;stdcall;
begin
result:=TMan.create;
end;exports
createMan;
begin
end.
主窗口单元。
unit uFromMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,uInterMain, StdCtrls,Activex, ScktComp;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
AMan:IMan;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1; //function createMan:IMan;stdcall;external 'pDllMain.dll';implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
createMan:function:IMan;stdcall;
ALibrary:Thandle;
begin
ALibrary:=LoadLibrary('pDllMain.dll');
try
if ALibrary=0 then
exit;
createMan:=GetProcAddress(ALibrary,PChar('createMan'));
if createMan=nil then
exit;
AMan:=createMan;
finally
freelibrary(ALibrary);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AMan.hello;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AMan:=nil;
end;end.运行后。。出错
EAccessViolation错误类型。
是怎么回事啊。
静态调用事可以的。
unit uInterMain;interfacetype
IMan=interface(IInterface)
['{F6F1A26D-7A7D-427D-820D-09B0B2F71407}']
procedure hello;end;implementationend.接口实现单元:
unit uOprMain;interfaceuses
uInterMain,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Activex, ScktComp,uDataMain;type
TMan=class(TInterfacedObject,IMan) public
procedure hello;
constructor create;
end;implementation constructor TMan.create;
begin
inherited create;
end; procedure TMan.hello;
begin
showmessage('asdf');
end;end.
dll单元。
library pDllMain;
uses
SysUtils,
Classes,
uInterMain in 'uInterMain.pas',
uOprMain in 'uOprMain.pas';{$R *.res}
function createMan:IMan;stdcall;
begin
result:=TMan.create;
end;exports
createMan;
begin
end.
主窗口单元。
unit uFromMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,uInterMain, StdCtrls,Activex, ScktComp;type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
AMan:IMan;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1; //function createMan:IMan;stdcall;external 'pDllMain.dll';implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
createMan:function:IMan;stdcall;
ALibrary:Thandle;
begin
ALibrary:=LoadLibrary('pDllMain.dll');
try
if ALibrary=0 then
exit;
createMan:=GetProcAddress(ALibrary,PChar('createMan'));
if createMan=nil then
exit;
AMan:=createMan;
finally
freelibrary(ALibrary);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AMan.hello;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AMan:=nil;
end;end.运行后。。出错
EAccessViolation错误类型。
是怎么回事啊。
静态调用事可以的。
解决方案 »
- delphi 5 使用TDatabase 通过BDE以windows验证方式 访问SQLSERVER数据库
- dbgrid问题
- 急 求一干部管理程序 高分相赠
- 急!!!如何在程序中对文字的输入法保持一至!
- 如何获取网卡信息?象控制面板里显示的一样。
- 求 html ubb 互转 例子
- 记录集中的记录如何复制和粘贴
- 版主,zswang,我刚看了My_first (海浪) 的几个贴子,给的什么分?我没搞懂?
- 请问谁有制作菜单巨好的工具,要for Delphi6的!急,急,急!!!
- 问个奇怪的问题!
- 急!~一个简单的SQL查询问题....................
- intraweb和ASP之类的语言相比较综合性能如何?
我再简化一下代码吧
dll代码。library pDllMain;
uses
SysUtils,
Classes;{$R *.res}function a:integer;stdcall;
begin
result:=1;
end;exports
a;
begin
end.
调用代码。var
a:function:integer;stdcall;
ALibrary:Thandle;
begin
ALibrary:=LoadLibrary('pDllMain.dll');
try
if ALibrary=0 then
exit;
@a:=GetProcAddress(ALibrary,PChar('a'));
if @a=nil then
exit;
showmessage(inttostr(a));
finally
freelibrary(ALibrary);
end;
老是运行到if @a=nil then
exit;
运行exit;也就是@a=nil 晕死了
這句有問題a:=GetProcAddress(ALibrary,'a');
好像是这一句声明有问题。记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
记得不能够定义接口对象吧!!
我上面所有的代码。。
把动态调用dll换成静态调用就没问题了。
怎么回事啊???????
,然后离开FormCreate以前,临时分配的IMan被调用_Release(),可是这时实现代码已经unload了,怎么能不出错呢?