用Delphi 5 调用 VC++ 6 的dll类中的函数出现问题(Access Violation)(100分)

  • 主题发起人 主题发起人 bood
  • 开始时间 开始时间
B

bood

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi 代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
...
type
TSample=class(TObject)
public
function ok():Boolean;virtual;cdecl;abstract;
end;

type
pTSample=^TSample;
var
Form1: TForm1;
pSample:pTSample;
function CreateInstance():pTSample;cdecl;far;external 'httpdll';
procedure DeleteInstance(psample:pTSample);cdecl;far;external 'httpdll';

implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
pSample:=CreateInstance();
pSample^.ok();
//调用时出现"Access Violation at..."对话框
DeleteInstance(pSample);
end;

end.

VC++代码:
declaration:
#define DllExport __declspec(dllexport)
extern "C" DllExport sample * __cdecl CreateInstance();
extern "C" DllExport void __cdecl DeleteInstance(sample * Instance);
class DllExport sample
{
public:
virtual BOOL __cdecl ok();
};

definitions:
BOOL __cdecl sample::ok()
{
MessageBox(NULL,"Hello","In Dll",0);
return 1;
}
extern "C" DllExport sample * __cdecl CreateInstance()
{
return (new sample);
}
extern "C" DllExport void __cdecl DeleteInstance(sample * Instance)
{
delete Instance;
}
 
楼上兄台,看看这里的观点吧,说是行不通
http://www.csdn.net/expert/topic/88/88183.shtm
 
提问者:
如果你还要继续讨论请定期提前你的帖子,如果不想继续讨论请结束帖子。
请认真阅读大富翁论坛规则说明
http://www.delphibbs.com/delphibbs/rules.asp
 
用接口吧
 
Sorry
好久没来,忘了
看来由于编译器的不同,只能用COM规范解决了
 
后退
顶部