Is it possible to pass a Delphi stream (TStream descendant) to a DLL written in c/c++? DLL will be written in Microsoft c/c++. If that is not possible, how about if we use C
interface
, for example. In general, wrapping up a Delphi class and presenting it as an interface
is not completely trivial. One reason why you can't just expose the raw methods via an interface is that the Delphi methods using the register
calling convention which is proprietary to Embarcadero compilers. You'd need to use a calling convention that is understood by the Microsoft compiler, e.g. stdcall
.
Another complication comes with exceptions. You would need to make sure that your interface methods did not throw exceptions since your C++ code can't be expected to catch them. One option would be to use Delphi's safecall calling convention. The safecall
calling convention is stdcall
but with an added twist that converts exceptions into HRESULT
values.
All rather straight forward in concept, but probably requiring a certain amount of tedious boilerplate code.
Thankfully, in the case of TStream
, you can use TStreamAdapter
to expose the Delphi stream as a COM IStream
. In fact, the source code for this small class shows how to handle the issues I describe above.