Link to home
Start Free TrialLog in
Avatar of bfjvr
bfjvr

asked on

Streaming Data between COM Objects

I need to stream data from one COM Object to another over a COM interface. The objects will be executables which could be running on separate machines. How do I declare and connect the streams within the objects ?? I have had a look at TOLEStream in Delphi5 , but the help gives little or no info.

Cheers,
Ben
******************
Hello all, thanks for the responses.
I need to state that the data I will be streaming is not intented to be used for the rebuilding of an object or component.

The data is captured from a serial port in Application1 and streamed to memory or file.

Application 2 connects to Application 1 and requests that the data be "streamed" to it , where it will be processed.
Avatar of Lischke
Lischke

listening...
Hi Ben...

are you dealing with an in or out of process server? If it's an in process server you could simply pass the a pointer to your stream object. I'm not too sure with an out of process server, but I think the only way there is to write your own marshaling mechanism (though there might be another way which I don't know).

Hope that helps... Jonny...
That's why I'm only listening here. I'm writing a control (a virtual treeview to be precise) which supports OLE drag'n drop. But I haven't got dragging between applications to work because of the expensive marshalling mechanism. For system stuff this is already there, so at least this is usable...

Ciao, Mike
what about using variant array of type varByte and send data check this function:

function VarArrayLoadFile(const FileName: string): Variant;
var
 F: file;
 Size: Integer;
 Data: PChar;
begin
 AssignFile(F, FileName);
 Reset(F, 1);
 try
   Size := FileSize(F);
   Result := VarArrayCreate([0, Size - 1], varByte);
   Data := VarArrayLock(Result);
   try
     BlockRead(F, Data^, Size);
   finally
     VarArrayUnlock(Result);
   end;
 finally
   CloseFile(F);
 end;
end;
Ben, do you have any COM/DCOM experience?
listening...
Hi Ben,

I would also think that using variant array of type varByte as kubeerja said should be able to do everything you would need. I even saw a sample of how you could write a component to a MemoryStream, stuff it into a VarArray and then on the other computer unpack the VarArray back to a MemoryStream and recreate the component from that stream.
In that example the component first executed some work on computer 1, was then marshalled to computer 2 and all the results produced on computer 1 wre available on computer 2.

Thomas

P.S. To Lischke:

Mike,

maybe this could help you:

Drag and Drop Component Suite by Angus Johnson, Anders Melander , freeware full source at http://www.melander.dk

Hi Thomas,

thank you for the link. Actually, I know the work of Anders because it was one of the sources I consulted when I implemented my own stuff. It is really good for standard stuff of the system, although it seems as would it have been created to provide as much as possible instead of as easy as possible.

Unfortunately, we are talking here about the really difficult stuff. Have you ever tried to pass your own interface along between different applications? Without marshalling you can't even get an interface which is derived from a standard interface. I, for instance, tried to extend IDragSource with an additional method. Through the default marshalling I got always only the normal IDragSource interface never my derived interface.

Ciao, Mike
Hi Mike,

I don't see where the problem is for passing interfaces between applications.
I did not try to pass my own interfaces between apps so far but at the moment I am writing some COM servers which I call from MS-Office apps by VBA.
In the last week I made a small test:
In my COM-server I Included an OLEVariant parameter to a method and in a macro which I call from word I created an instance of my server and passed a Variant which was actually a WordDocument Interface to my server.
In my server I was able to cast the OLEVariant back to the Document-Interface and access it completely via early binding. (Of course I had to include the Word.TLB in my code)
Shouldn't something simular work for you too?

Thomas
Avatar of bfjvr

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of kubeerja
kubeerja

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
function MemoryStream2Var(Const MStream:TMemoryStream):OleVariant;
var P:Pointer;
begin
    Result:=VarArrayCreate([0,MStream.Size-1],varByte);
    P:=VarArrayLock(Result);
    try
      Move(MStream.Memory^,P^,MStream.Size);
    finally
      VarArrayUnlock(Result);
    end;
end;

HTH,

Thomas
Avatar of bfjvr

ASKER

Seems like a variant array is the way to go then.

Thanks to all.