Delphi出現"Invalid pointer operation"異常的解決辦法

Delphi使用dll跨進程傳遞長字符串或動態數組,常常會出現invalid pointer operation的錯誤提示。數組


解決方法: 將DLL工程文件和調用的程序工程文件, USE 後第一個位置,添加引用ShareMem單元,使應用程序能夠和DLL共享地址空間。app

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.
字符串

相關文章
相關標籤/搜索