Reputation: 76557
I'm hooking a few functions from DbkDebug240.bpl
into a IDE plugin.
The hooking works fine, but I need to use some string data.
The problem is that DbkDebug*.bpl
does not use ShareMem; i.e. it does not import BorlndMM.dll
. This causes problems because I'd like to call functions that return strings, but I cannot do this without causing exceptions.
I can 'fix' this by lying (i.e. use PChar
), but then I get leaks.
example:
function GetExceptionMessage: Unicodestring; external 'Dbk240.bpl'
name '@Debug@TDebugger@GetExceptionMessage$qqrv';
//causes exceptions further down the line.
function GetExceptionMessage: PChar; external 'Dbk240.bpl'
name '@Debug@TDebugger@GetExceptionMessage$qqrv';
//I think this causes a leak futher down the line.
Is there a way to call functions that returns strings from a dll that does not use ShareMem in a way that does not leak?
The problem is that my plugin is in a DLL. I guess I can hook the DLL's memory manager's functions into those of the IDE, that would solve the issue.
Upvotes: 0
Views: 310
Reputation: 612934
This is a package, you don't need to use ShareMem. Instead you link with runtime packages, making sure that you link to the rtl package. Because your code links to the rtl package, you naturally share the runtime, including the memory allocator.
I guess I can hook the DLL's memory manager's functions into those of the IDE, that would solve the issue.
That seems to be the wrong way round. You just need to arrange that your DLL links against runtime packages.
Upvotes: 3