yes it is inter process communication. can you point me to any example of sending image between apps.
another option i think of is to convert the image to series or string, of which i'll need assistance too
Programming is all about good logic. Spend more time here
For example if you are talking about a StdPicture object (such as the .Picture property of a PictureBox, Form, etc.) then the issues are somewhat different than if you have an image as a persisted image file format (like a .JPG, .GIF, .BMP file).
You need to say more about what you actually have to send from the sender and what you want to receive at the receiver.
Most forms of IPC are going to require that you deal with serialization and deserialization. If your sender has a Byte array that contains a standard image file format and your receiver can use such a Byte array when it gets it - then things are simplified a lot. But for most VB programs that will not be the case for either end.
Sending either .BMP file format data or even a raw RGB bitmap (almost the same thing) can be fast "within a computer" because there is less compression and decompression code that must run. However "between computers" this is slow because the size of the data is large and even a fast LAN is relatively slow.
TCP/IP might be the simplest way you could go in VB6. But even there you can have complications to deal with, such as trying to do peer-to-peer instead of client-server.
Maybe you can work something out from this example. It does peer-to-peer picture sending between two copies of itself running on the same PC.
If you really want to read a file and send it and write it back to disk... well then you can simplify the program a little. At least you won't need the PropertyBags, though most of the rest would need to stay.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
thatns, but this dosent work for me, i need to send this as a string instead
*sigh*
Send what "as a string?" You still don't seem to be able to express what you need to do here.
Send the name of a file as a string? Well if the two programs run on the same machine that should work fine. No reason to do something silly like read the file in one program and send the contents to the other one.
Send the data as a string? Well if these two programs are on the same machine just send the file name. Didn't I just cover that?
Any particular reason why Dilettante's code doesn't work for you ? It seems to do what it says on the Tin - at least it does for me. Is the receiving program perhaps associated with one of your other Threads regarding a Console Application ? Perhaps you could answer the following to give a better idea of the environment:
1. Is a bi-directional transfer required?
2. Are both Programs Windows Forms Applications?
3. What is the receiving Application going to do with the Image once it has been received? (ie Display it, Save it as a file, Throw it away)
4. What sort of size image are you sending? (that could affect the selection of the most appropriate IPC to use)
Whilst it may work, your current proposed strategy of sending it as a string seems like a waste of Bandwidth and CPU Cycles.
Private Sub Form_Load()
Set pbRcv = New PropertyBag
Set pbSend = New PropertyBag
Set stmRcv = New ADODB.Stream
With stmRcv
.Open
.Type = adTypeBinary
End With
InitiateTcp
End Sub
Last edited by firoz.raj; Sep 2nd, 2012 at 06:55 AM.
The PropertyBag is used to take advantage of COM serialization without using COM between the two programs (which would require that one of them be an ActiveX EXE, or that there be a 3rd ActiveX EXE program to act as a broker between the other two programs). The reason for doing this is to make it easy to move a StdPicture object between the two programs using any arbitrary form of communication between them.
The ADO Stream object is just a simple way to handle data stream reassemly. You could do the same thing using a typelib providing the IStream interface, or you could "roll your own" stream based on Byte arrays.
The reason for shipping a StdPicture is that the source image might have been something created by the sending program at runtime, i.e. by using VB drawing methods and such.
If the image is merely being read from a disk file and not created dynamically I'm not sure why you'd need any fancy IPC at all. It should be enough to simply send the file name from one program to the other, no need to ship all of the bytes across the link. Program2 can open the file as easily as Program1 can!
If the image is not dynamically created, and is not present on disk, I'm not sure what that leaves. Perhaps an image resource? If you have that, and you are writing both programs, then why not just include the resource in the program that needs it?
It is still extremely unclear what is being asked for here.
Are both programs actually going to be running on the same computer? Do these programs need all of the extra effort required to simulate peer-to-peer, bi-directional operation or does this 'image sending" only have to go from one to the other?
If the image is merely being read from a disk file and not created dynamically I'm not sure why you'd need any fancy IPC at all.
thanks for this idea, i'll use this for the image
what about sending large test between the two apps using IPC?
one app generates array of udtInfo which needs to be sent to the other app the UDT is defined like this
Code:
Type udtInfo
FileName as string
ThumbnailPath as string
Title as string
End Type
the problem still comes down to the fact that i need to send large text between the two apps
Programming is all about good logic. Spend more time here
byte array to string.. very useful for transforming bytes stream to string.
but byte array must only contain string bytes.. nothing else it could also be terminated by 0 byte.. which it will remove.
Code:
Public Function ByteArrayToString(bytArray() As Byte) As String
Dim sAns As String
Dim iPos As String
sAns = StrConv(bytArray, vbUnicode)
iPos = InStr(sAns, Chr(0))
If iPos > 0 Then sAns = Left(sAns, iPos - 1)
ByteArrayToString = sAns
End Function
And this one works opposite
Code:
Dim bytArray() As Byte
Dim str As String
str = "Some String To before byteArray"
bytArray = StrConv(str, vbFromUnicode)
can you point me to any or give me keywords to search
If you can't see how to mofidy Dilettante's code, there's a really simple example of how to send a UDT via Winsock here: http://support.microsoft.com/kb/152058
Be careful to read the notes as it wont work properly as is. The methodology is basically to convert the UDT to a Byte Array and send it. (Which, I think, brings us back to your original problem)
We have a Terminology problem then. I understand IPC to be 'Inter-Process Communication'; the use of Winsock is one method, of many, that can be used to implement IPC.
That's a fairly important piece of information to come out this late in the game. (especially as in your original Post you stated that they both were VB6 Applications)
Delphi supports Sockets so it wouldn't be too difficult a problem to use Winsock in the VB Program and the indy TCP components in Delphi, you'll just have to develop an Application Protocol which both applications understand. See here: http://www.delphisources.ru/pages/fa...t/LiB0189.html for something on Delphi Sockets.
Another option is to dump your UDT array to a file and get the Delphi Application to read it once it's created. I assume there are facilities in Delphi to check for the existence of a file.
Yet another option might be to use the WM_COPYDATA Windows Message as I understand Delphi can process it. The VB program could send each string using the SendMessage API. See: http://delphi.about.com/od/windowssh...m_copydata.htm - which shows how to process the message in Delphi.