是不是dll调用Com+接口会有问题? ( 积分: 100 )

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

hophy

Unregistered / Unconfirmed
GUEST, unregistred user!
我的com接口定义如下:
CoAppPublicServer = class
class function Create: IAppPublicServer;
class function CreateRemote(const MachineName: string): IAppPublicServer;
end;

dll定义如下:
procedure test(AParam: Pchar);
stdcall;
var
IAPS: IAppPublicServer;
begin
IAPS := CoAppPublicServer.CreateRemote('128.111.100.210');
end;

exports
test;
客户端程序:
procedure test(AParam: Pchar);
stdcall;
external 'test.dll';
procedure TForm1.Button4Click(Sender: TObject);
begin
test('aaa');
end;

Button4按下一次后退出客户端程序不会出错,但只要多按一次,退出时会弹出(不退出程序不会出错):
“Project d:/TestDll.exe raised too many consecutive exceptions:'access violation at 0x004138e2:read of address 0x01084474'.Process Stopped. Use Step or Run to continue.”
有谁能告诉我是什么原因?怎么解决呢?
 
我的com接口定义如下:
CoAppPublicServer = class
class function Create: IAppPublicServer;
class function CreateRemote(const MachineName: string): IAppPublicServer;
end;

dll定义如下:
procedure test(AParam: Pchar);
stdcall;
var
IAPS: IAppPublicServer;
begin
IAPS := CoAppPublicServer.CreateRemote('128.111.100.210');
end;

exports
test;
客户端程序:
procedure test(AParam: Pchar);
stdcall;
external 'test.dll';
procedure TForm1.Button4Click(Sender: TObject);
begin
test('aaa');
end;

Button4按下一次后退出客户端程序不会出错,但只要多按一次,退出时会弹出(不退出程序不会出错):
“Project d:/TestDll.exe raised too many consecutive exceptions:'access violation at 0x004138e2:read of address 0x01084474'.Process Stopped. Use Step or Run to continue.”
有谁能告诉我是什么原因?怎么解决呢?
 
好像不是dll调用com的问题
procedure TForm1.Button4Click(Sender: TObject);
begin
test(pchar('aaa'));
end;
可以吗?
 
procedure test(AParam: Pchar);
stdcall;
var
IAPS: IAppPublicServer;
begin
IAPS := CoAppPublicServer.CreateRemote('128.111.100.210');
IAPS := nil ;
//试试
end;
 
jettop,
接口是生存期自管理的
上例显然是pchar越界问题
 
接受答案了.
 
后退
顶部