大家帮我看一下
Dll 工程
library ypdll;
uses
SysUtils,
Classes,
Unit_dll in 'Unit_dll.pas' {Frm_dll};
exports
BeforeCreate,
AfterFree,
Getmsg;
{$R *.res}
begin
end.
---------------------------
Dll 里一个form
unit Unit_dll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB;
type
TFrm_dll = class(TForm)
ADOConnection1: TADOConnection;
ASPDll: TADOStoredProc;
private
{ Private declarations }
public
{ Public declarations }
end;
Function Getmsg(Atd_id:string)
char
stdcall ;
procedure BeforeCreate
stdcall;
procedure AfterFree
stdcall;
var
Frm_dll: TFrm_dll;
implementation
{$R *.dfm}
{ TFrm_dll }
{ TFrm_dll }
function Getmsg(Atd_id: string): pchar
stdcall;
var
str:string;
begin
Frm_dll.ASPDll.Close;
Frm_dll.ASPDll.Parameters.ParamValues['@td_id']:=strtoint(Atd_id);
Frm_dll.ASPDll.Parameters.ParamValues['@td_name']:='' ;
Frm_dll.ASPDll.Parameters.ParamValues['@td_birthday']:=date() ;
Frm_dll.ASPDll.Parameters.ParamValues['@td_memeo']:='' ;
Frm_dll.ASPDll.Parameters.ParamValues['@td_type']:='' ;
Frm_dll.ASPDll.ExecProc;
str:= Frm_dll.ASPDll.Parameters.ParamValues['@td_name']+'|'+datetostr(Frm_dll.ASPDll.Parameters.ParamValues['@td_birthday'])
+ '|'+Frm_dll.ASPDll.Parameters.ParamValues['@td_memeo']+'|'+Frm_dll.ASPDll.Parameters.ParamValues['@td_type'];
result:=pchar(str);
end;
procedure BeforeCreate
stdcall;
var
Frm_dll:Tform;
begin
if assigned(Frm_dll) then exit;
Frm_dll:= TFrm_dll.Create(application) ;
Frm_dll.Hide;
end;
procedure AfterFree
stdcall;
begin
if assigned(Frm_dll) then freeandnil(Frm_dll);
end;
end.
------------------------------------------------
exe 工程
program Id;
uses
Forms,
Unit_Id in 'Unit_Id.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
------------------------------------------------------
exe form
unit Unit_Id;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Function Getmsg(Atd_id:string)
char
stdcall
external 'ypdll.dll';
procedure BeforeCreate
stdcall
external 'ypdll.dll';
procedure AfterFree
stdcall
external 'ypdll.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
BeforeCreate;
Memo1.Clear;
Memo1.SetSelTextBuf(Getmsg(trim(Edit1.Text)));
end;
procedure TForm1.FormClose(Sender: TObject
var Action: TCloseAction);
begin
AfterFree;
end;
end.
-----------------------------------------
调函数时出错,提示:尚未调用Coinitialize