unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
   // function ado1(yunbian:string;udl:string):string;stdcall;
  private    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
     function ado1(yunbian:string;udl:string):string;stdcall;external'ADO.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
       showmessage(ado1('aa','Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=db_export;Data Source=notebook'));
end;end.DLL:
library ADO;{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;{$R *.res}function ado1(yunbian:string;udl:string):string;stdcall;
var
tql:TADOquery;
adoc:TADOConnection;
begin     adoc:=TADOConnection.Create(application);
     adoc.Close;
     adoc.ConnectionString:=udl;
     adoc.Open;
     tql:=TADOquery.Create(application);
     tql.Connection:=adoc;
     tql.Close;
     tql.SQL.Clear;
     tql.SQL.Add('select * from t_consign');
     tql.Open;
     if not  tql.Eof then
        result:=tql.Fields[1].AsString;     adoc.Free;
     tql.Free;
end;
exports
     ado1;
beginend.
当showmessage后,数据是显示出来了解,可是接着又出现 'Invalid Pointer operation' 请教!

解决方案 »

  1.   

    function ado1(yunbian:string;udl:string):string;stdcall;external'ADO.dll';
    参数改为pchar申明试试function ado1(yunbian:pchar;udl:pchar):pchar;stdcall;external'ADO.dll';
      

  2.   

    yunbian:string;参数好象没用
      

  3.   

    function ado1(yunbian:string;udl:string):string;stdcall;
    改为如下方式声明试试
    function ado1(yunbian:pchar;udl:pchar):pchar;stdcall;
      

  4.   

    to: jiju(UNCC)
     还是不行
      

  5.   

    传的是String类型,要包含ShareMem单元,并放在第一个,工程中也是,下面是理由
    { Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }
      

  6.   

    to : ljmanage(过客) 
      谢谢你,在dll中加了一个sharemem,在工程中也加了一个,都是在第一个位置,
      当单击时没有错误可是当我关闭窗体时,还是出现这个错误'Invalid Pointer operation' 
    并且又附加一个错误:Runtime error 217 at 0041bb60
      

  7.   

    你用的是ADO,就是相当于用了Activex控件function ado1(yunbian:string;udl:string):string;stdcall;
    var
    tql:TADOquery;
    adoc:TADOConnection;
    begin     coInitialize(nil);  //加上
         adoc:=TADOConnection.Create(application);
         adoc.Close;
         adoc.ConnectionString:=udl;
         adoc.Open;
         tql:=TADOquery.Create(application);
         tql.Connection:=adoc;
         tql.Close;
         tql.SQL.Clear;
         tql.SQL.Add('select * from t_consign');
         tql.Open;
         if not  tql.Eof then
            result:=tql.Fields[1].AsString;     adoc.Free;
         tql.Free;
         CoUninitialize;  //加上
    end;
    exports
         ado1;
    beginend.
      

  8.   

    .Create(application);错在这句,应为.Create(nil)
    或在exe中把Application.handle传入
    在Dll里
    application.handle := 你传入的handle;
    里面就可以用.Create(application);
      

  9.   

    Dll里的Application 和exe中的application不同的,传入赋值后就同了
      

  10.   

    to: ljmanage(过客)   谢谢可,是程序说  coInitialize  没定义
      

  11.   

    我加了ActiveX可以是可以,但是还是不行,还是出现这个错误