• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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.
0
bfjvr
Asked:
bfjvr
  • 3
  • 3
  • 2
  • +4
1 Solution
 
LischkeCommented:
listening...
0
 
jonnyfiveCommented:
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...
0
 
LischkeCommented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kubeerjaCommented:
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;
0
 
EpsylonCommented:
Ben, do you have any COM/DCOM experience?
0
 
mathoughtCommented:
listening...
0
 
xsoftCommented:
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

0
 
LischkeCommented:
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
0
 
xsoftCommented:
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
0
 
bfjvrAuthor Commented:
Edited text of question.
0
 
kubeerjaCommented:
as I mentioned before you can send it as variant array and in the other side converted back to buffer and write it into a memory stream or file as here in this code :

procedure VarArraySaveFile(const FileName: string ; varData : Variant);
var
 F: file;
 Size: Integer;
 Data: PChar;
begin
 if not VarIsArray(varData) then
 begin
  messagedlg('Wrong Variant format',mtError,[mbOK],0) ;
  exit ;
 end ;
 AssignFile(F, FileName);
 ReWrite(F, 1);
 size:=VarArrayHighBound(varData,1)+1 ;
 try
   Data := VarArrayLock(varData);
   try
     BlockWrite(F, Data^, size);
   finally
     VarArrayUnlock(varData);
   end;
 finally
   CloseFile(F);
 end;
end ;
0
 
xsoftCommented:
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
0
 
bfjvrAuthor Commented:
Seems like a variant array is the way to go then.

Thanks to all.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now