在dll中不要使用string类型作为函数返回值,你新建个dll项目时,项目文件中开头大段的提示就告诉你了
// dll
library Project1;
{ 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. } // string 改用 pchar 替代,如果你一定要使用 string类型,那么在项目最开头
uses
  ShareMem, // 加入该单元,并且必须是放在第一位
  SysUtils,
  Classes;
// 在调用处的项目单元开头也必须这样做// exe
program Project2;
 
uses
  ShareMem, // 加入该单元,并且必须是放在第一位
  Forms,
  Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
//  最后,发布程序后必须把 BORLNDMM.DLL 一并打包发布(把BORLNDMM.DLL置于发布的程序的目录中),
// BORLNDMM.DLL 在 ...\delphi\bin\ 下就能找到btw  pure virtual function call 调用了纯虚函数,这个错误俺还没见过

解决方案 »

  1.   


    { 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. }{关于DLL内存管理的重要提示:如果你的过程或函数中使用 string 作为参数
    或者返回值的话,那么 ShareMem 必须在你的DLL和项目的 uses 引入列表
    中的第一位置,(选择 project-view source)。这适用于所有从DLL中传递
    string 对象的情况,即便该 string 只是 record(记录)或是 class(类)
    中的成员也需要如此。ShareMem 是 BORLNDMM.DLL 中定义的一个接口单元,
    它必须跟你的 DLL 一同部署。如果不想使用 BORLNDMM.DLL,那么传递字符串
    类型参数应该使用 Pchar 或者 ShortString 类型。}
      

  2.   

    很多人无视该段提示,照样用string也不uses sharemem,他们也会说没出错啊,那不是 没出错,是 还没出错。
    string类型是delphi中的独有类型,它不是一种兼容的类型,它由delphi管理其生命周期,具体来说在DLL中的string就是由BORLNDMM.DLL 中的 sharmeme这个单元中的代码来负责管理内存的,sharemem中定义了一个内存管理器,这个内存管理器随BORLNDMM.DLL加载而加载,由它来管理string类型的生命周期。LZ如果没有这样做最好照做。但是根据最后的错误提示,那是c++运行时错误,原因是调用了纯虚函数,delphi中大量使用了inteface,而c++中没有interface,c++是通过用纯虚类来实现同样的功能,提示调换了纯虚类很可能就是dll没有提供interface的实现代码或反之。仔细看这个帖子,应该有帮助