如果你的dll需要传递动态数组, 就必须加上sharemem单元,
具体请看下面If a DLL exports routines that pass long strings or dynamic arrays as parameters or function results (whether directly or nested in records or objects), then the DLL and its client applications (or DLLs) must all use the ShareMem unit. The same is true if one application or DLL allocates memory with New or GetMem which is deallocated by a call to Dispose or FreeMem in another module. ShareMem should always be the first unit listed in any program or library uses clause where it occurs.ShareMem is the interface unit for the BORLANDMM.DLL memory manager, which allows modules to share dynamically allocated memory. BORLANDMM.DLL must be deployed with applications and DLLs that use ShareMem. When an application or DLL uses ShareMem, its memory manager is replaced by the memory manager in BORLANDMM.DLL.

解决方案 »

  1.   

    问题见文章:DLL中能不能不用ShareMem单元?
    谢谢Tiger的回答,
    你贴的那段文章我似乎在help中看过。依你的建议,我应该如何修改我的程序呢?
    Function a:PChar;能不能修改成Procedure a(out return: PChar)来避开
    "If a DLL exports routines that pass long strings or dynamic arrays as parameters or function results (whether directly or nested in records or objects), "中function result的限制?这我可以试一下,但是动态数组我又该用什么替代,最好是在VC++中能用char*[]来引用?
    char*[]是不是很类似Array of PChar???
      

  2.   

    我想应该没用的, 应为as parameters 也要用sharemen
      

  3.   

    Sharemee单元是DELPHI为了进行字符串的优化处理而设的。DELPHI中的ANSISTRING,WIDESTRING等字符串类型都是动态分配,并且引用计数的。通过这样的处理,可使字符串的处理速度大大加快。如果在DLL中完全脱离DELPHI的字符串处理及内存分配功能,而以API函数实现,我想在DLL中不用SHAREMEM单元完全是可以的。比如说通过文件映射(FILEMAPING)、虚存分配函数来实现。
      

  4.   

    最好不要采用ShareMem单元,否则经常会导致异常错误的发生.
    由于Delphi本身的问题,在模块间或是DLL间传递复杂变量类型
    会使接收方无法正常接收.
    采用PChar而不是String在模块间传递字符串,因为String在Delphi中也是复杂类型.