Solved

Streaming Data between COM Objects

Posted on 2000-04-14
13
467 Views
Last Modified: 2012-05-04
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
Comment
Question by:bfjvr
  • 3
  • 3
  • 2
  • +4
13 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2715940
listening...
0
 

Expert Comment

by:jonnyfive
ID: 2716247
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
 
LVL 10

Expert Comment

by:Lischke
ID: 2716288
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 2

Expert Comment

by:kubeerja
ID: 2716381
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 2717722
Ben, do you have any COM/DCOM experience?
0
 

Expert Comment

by:mathought
ID: 2718746
listening...
0
 
LVL 1

Expert Comment

by:xsoft
ID: 2720754
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
 
LVL 10

Expert Comment

by:Lischke
ID: 2720829
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
 
LVL 1

Expert Comment

by:xsoft
ID: 2720972
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
 

Author Comment

by:bfjvr
ID: 2721711
Edited text of question.
0
 
LVL 2

Accepted Solution

by:
kubeerja earned 300 total points
ID: 2722754
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
 
LVL 1

Expert Comment

by:xsoft
ID: 2724119
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
 

Author Comment

by:bfjvr
ID: 2725531
Seems like a variant array is the way to go then.

Thanks to all.

0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question