The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,779 other followers

Don’t pass interfaces between application architectures over a DLL boundary

Posted by jpluimers on 2013/05/15

It is unwise to pass objects allocated in one framework over a DLL boundary to a different framework.

In the case of Using C dll in delphi return nothing, someone tries to pass an Interface to some memory in the C side over to Delphi.

Unless that interface is COM based, don’t do that!

In a more general way: don’t pass memory allocated on the DLL side over to the client side, no matter what kind of client you have.

From the DLL, either pass simple types, or fill buffers allocated at the client side.

Edit:

There was a nice Delphi DLL return string from C# … .NET 4.5 Heap Corruption but .NET 4.0 works? Explain please? – Stack Overflow question explaining in detail what to do for strings in a specific case: use the COM heap on the Delphi side using CoTaskMemAlloc (actually it uses the OLE task memory allocator as the Old New Thing explains).

–jeroen

via: Using C dll in delphi return nothing – Stack Overflow.

5 Responses to “Don’t pass interfaces between application architectures over a DLL boundary”

  1. IL said

    Does passing interface from one BPL to the other BPL count as crossing DLL boundary?
    What about passing interface from EXE/BPL to common DLL compiled with FastMM4 and UseRuntimePackages defined?

    • jpluimers said

      Though BPL are technically DLL, they share the RTL.
      EXE/BPL also shares the RTL.
      But BPL/DLL can potentially have different RTL. So I’m not sure about the UseRuntimePacakges define in FastMM: have not tried that yet.

  2. Sebastian Jänicke said

    The problem discussed at Stack Overflow is not, that an interface cannot be passed or retrieved by using a DLL call. The problem is that Delphi calls such functions in another way than C (though it is the same calling convention). I also experienced this problem, but it was no problem to use the interface once I managed to get the interface correctly (using assembly language).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: