Subject Re: [IBO] To use TIB_ as parameter DLL, need to use ShareMem or SimpleShareMem in uses clause?
Author Geoff Worboys
hamacker sirhamacker@... [IBObjects] wrote:
> Hi everybody,

> Who knows if is necessary to declare  ShareMem or
> SimpleShareMem in uses clause when I need to pass
> IB_Connection by parameter as :

> function ModuloRodar(MyConn:TIB_Connection;sParam:WideString):
> WideString; stdcall;

It would seem unusual to pass Delphi component references
between a DLL and an application (in either direction). The
normal method would be to use runtime packages - in which case
ShareMem is not relevant. But if you were using a DLL, for
whatever reason, then it might be expected that the DLL would
have been built with the same Delphi compiler, in which case
you are probably already using the same memory memory manager
so ShareMem shouldn't matter. If the DLL is not from Delphi it
would be more common to pass the Firebird database handle
across to the DLL rather than the full connection component.

But what is usual or unusual aside, it's all about memory
management. The reason why can be is necessary for long string
and dynamic arrays is that their memory management is automatic
so you don't have much control over when they might reallocate
or free memory. (Although, in a typical DLL scenario it is
feasible to send pointers into arrays/strings across the DLL
link without needing ShareMem as long as you know there will
be no reallocations while it is in use across the interface and
you know the interface won't retain pointers into the memory.
This sort of thing happens all the time in IBO as it interacts
with the fbclient.dll.)

If your DLL is creating any Delphi components for use by an
application, or the application is creating components for use
by the DLL, then ShareMem will be necessary unless that shared
use avoids anything that might cause memory (re)allocations on
either side while the object is in use (and knowing that means
being familiar with the source on both sides).

And regardless of all that, in the example above you pass and
return WideString, so ShareMem would be necessary.

--
Geoff Worboys
Telesis Computing Pty Ltd