Delphi出现"Invalid pointer operation"异常的解决办法

Delphi使用dll跨进程传递长字符串或动态数组,经常会出现invalid pointer operation的错误提示。


解决方法: 将DLL工程文件和调用的程序工程文件, USE 后第一个位置,添加引用ShareMem单元,使应用程序可以和DLL共享地址空间。

DELPHI 帮助文件解释如下:

On Windows, 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.

你可能感兴趣的:(Delphi出现"Invalid pointer operation"异常的解决办法)