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;
pSampleTSample;
function CreateInstance()TSample;cdecl;far;external 'httpdll';
procedure DeleteInstance(psampleTSample);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:k()
{
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;
}
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;
pSampleTSample;
function CreateInstance()TSample;cdecl;far;external 'httpdll';
procedure DeleteInstance(psampleTSample);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:k()
{
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;
}