Menu

Sharing memory between Delphi and .NET

2002-05-30
2002-06-01
  • Jérôme Tremblay

    I want to share memory between my program and an assembly.

    Using your wonderful unit, I can quite easily call my static methods with "simple" parameters. But now I am trying to pass the reference to an IStream interface created in my delphi program, invoke .net, modify the stream and retrieve it in the delphi program. Since there is potentially a huge amount of data, copying it to another stream or a fixed buffer is not an option. The .net module can also change the size of that stream.

    I found out the UCOMIStream interface of .net and tried to modify the CArrayToVArray method to handle interfaces, but have not been very sucessful yet.

    I create the stream in delphi like this:

    var
      stringStream: TStringStream;
      stream: IStream;
    begin
      stringStream := TStringStream.Create('Hello world!');
      stream := TStreamAdapter.Create(stringStream, soOwned);

    So far, I have been unable to pass an interface from delphi to .net. Any idea? And maybe there is a better way to share memory?

     
    • Marcus Schmidt

      Marcus Schmidt - 2002-05-31

      I have modified the DotNetExec.dll and .pas a little bit so that they can transport interfaces from Delphi to .NET. Also copying data from an IStream succeeded :)

      But there's one serious problem: Interfaces can only be accessed by .NET if there's a managed representation available for it. For example the "old" IStream interface has an ready-made managed representation, UCOMIStream as already mentioned. So objects that implement the IStream interface have to be queried the UCOMIStream by DotNetExec.

      imo it's not possible to determine the managed correspondent for an unmanaged interface - especially for user defined interfaces !
      So the according managed interface has to be identified in another way. Do you have an idea how would simplify the correlation of a unmanaged to a managed interface ?

      I could think of one way right away that doesn't seem to be very comfortable:
      Inside the DotNetExec.dll all incoming unmanaged interfaces are assigned to a managed interface by a built-in list that handles all interfaces that have a predefined managed declaration in the .NET framework.
      A user can also register custom interfaces to be resolved to a specified managed interface declaration (via a new function like "NETRegisterCorrespondingInterface" that takes the guid of the unmanaged interface and the location of the managed declaration as arguments).

      I hope someone has a better idea :>

       
      • Marcus Schmidt

        Marcus Schmidt - 2002-05-31

        Sorry for that crap ... I think the problem is quite easy to handle :>

         
      • Jérôme Tremblay

        How did you create your stream before passing it to .net? And were you able to read back the changes once the control is returned to your application? I got an access violation when I tried it.

         
        • Marcus Schmidt

          Marcus Schmidt - 2002-05-31

          I had modify DotNetExec ... I'll upload it to the cvs in some minutes.

          reading back: not tested yet :(

           
          • Marcus Schmidt

            Marcus Schmidt - 2002-06-01

            hmm modifying the stream seems to work but I think I need more time for the changes as expected :(

             
    • Marcus Schmidt

      Marcus Schmidt - 2002-06-01

      Hi,

      I've uploaded a new DotNetExec version (not completely tested yet) that sould be able to handle events.
      If you encounter problems please contact us :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.