//////////dll中是这样声明的:
function ReadDbInfo(section:string;databasetype:integer):string;
var
   MyIniFile: TIniFile;
   PassWord,UserID,DataSource,Defaultdb,ss:string;
begin   MyIniFile := TIniFile.Create('C:\CJSMS\DBINFO.ini');
   if databasetype=1 then
   begin
      with MyIniFile do
      begin
       Password:=ReadString(Section, 'PassWord','000000');
       userid:=ReadString(Section, 'USERID','000000');
       DATASOURCE:=ReadString(Section, 'DATASOURCE','000000');
      end;      result:='Provider=MSDAORA.1;Password='+PASSWORD+
        ';User ID='+USERID+';Data Source='+
        DATASOURCE+';Persist Security Info=True';
   end
   else begin
      with MyIniFile do
      begin
       Password:=ReadString(Section, 'PassWord','000000');
       userid:=ReadString(Section, 'USERID','000000');
       DATASOURCE:=ReadString(Section, 'DATASOURCE','000000');
       DEFAULTDB:= ReadString(Section, 'DATABASE','000000');
      end;
     result:='Provider=SQLOLEDB.1;Password='+PASSWORD+';Persist Security Info=True;User ID='+USERID+
       ';Initial Catalog='+DEFAULTDB+';Data Source='+DATASOURCE;
   end;
   MyIniFile.Free;
   
end;
//////////////////////unit中的声明及引出unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
Function ReadDBinfo(section:string;databasetype:integer):string;
var
  Form1: TForm1;implementation
function ReadDBinfo; external 'sms' index 4;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
 memo1.Lines.Add(readdbinfo('Ora_48',1));
end;end.调用时出现错误,"Invalid pointer operation"

解决方案 »

  1.   

    dll中的声明改为Pchar,看看api的声明你就知道了
      

  2.   

    兩邊都uses ShareMem 
    就可
      

  3.   

    只是返回值改为pchar,还是所有的都要改呀?
      

  4.   

    参数改成Pchar的,其他的都不用改
      

  5.   

    delphi使用dll时,请将你们的string全部改为PChar
      

  6.   

    代碼都不用改,就是直接用 
    uses shareMem;
      

  7.   

    用PCHAR和STRING差不多   uses shareMem有的时候会出错  而且你编译后还需要把borlandmm.dll拷贝到你的程序目录下才可以发布到没有delphi的环境中
      

  8.   

    pchar好和C的 CHAR*容易接轨!
      

  9.   

    我也遇到了同样的问题,调用时出现错误,"Invalid pointer operation"
    楼主,只要在调用的工程和dll的uses第一行加上ShareMem,再将borlandmm.dll放到工程文件夹下就搞定了。
    program prjCallMyDLL;uses
      ShareMem,
      Forms,
      untMain in 'untMain.pas' {Form1};{$R *.res}begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.library MyDLL;{ 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
      ShareMem,
      SysUtils,
      Classes
      Unit1 in 'Unit1.pas';{$R *.res}exports
      ReadDbInfo;begin
    end.