L
liuchong
Unregistered / Unconfirmed
GUEST, unregistred user!
//DLL代码(Dll中有
DataModule1;
con1: TADOConnection;
qry1: TADOQuery;
ds1: TDataSource;)
library MyDll;
uses
SysUtils,
Classes,
DB,
DM1 in 'DM1.pas' {DataModule1: TDataModule};
{$R *.res}
type
PDataSource=^TDataSource;
function GetDataSource()DataSource;stdcall;
begin
with DataModule1.qry1 do
begin
SQL.Clear;
SQL.Add('SELECT * FROM AA');
Open;
end;
Result:=PDataSource(DataModule1.ds1);
end;
exports
GetDataSource;
begin
end.
exe中的代码:
implementation
{$R *.dfm}
type
PDataSource=^TDataSource;
var
H:THandle;
GetDataSource:function()DataSource;stdcall;
procedure TForm1.btn1Click(Sender: TObject);
begin
H:=LoadLibrary('MyDll');
@GetDataSource:=GetProcAddress(H,'GetDataSource');
dbgrd1.DataSource:=GetDataSource()^;
end;
调用DLL出现内存错误,不知为何
DataModule1;
con1: TADOConnection;
qry1: TADOQuery;
ds1: TDataSource;)
library MyDll;
uses
SysUtils,
Classes,
DB,
DM1 in 'DM1.pas' {DataModule1: TDataModule};
{$R *.res}
type
PDataSource=^TDataSource;
function GetDataSource()DataSource;stdcall;
begin
with DataModule1.qry1 do
begin
SQL.Clear;
SQL.Add('SELECT * FROM AA');
Open;
end;
Result:=PDataSource(DataModule1.ds1);
end;
exports
GetDataSource;
begin
end.
exe中的代码:
implementation
{$R *.dfm}
type
PDataSource=^TDataSource;
var
H:THandle;
GetDataSource:function()DataSource;stdcall;
procedure TForm1.btn1Click(Sender: TObject);
begin
H:=LoadLibrary('MyDll');
@GetDataSource:=GetProcAddress(H,'GetDataSource');
dbgrd1.DataSource:=GetDataSource()^;
end;
调用DLL出现内存错误,不知为何