Results 1 to 24 of 24

Thread: [RESOLVED] Send image betweeb two apps using IPC

  1. #1

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Resolved [RESOLVED] Send image betweeb two apps using IPC

    i have two vb6 apps communication through IPC, i need to send an image between the apps. the image is not very large, usually less that 100KB

    how can i achieve this?
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    "IPC" is a very broad term. Without more details regarding the constraints you have it is very hard to do anything but make random suggestions.

    See Interprocess Communications

    Some of the options available are easier to write in VB, while some are more work but may have fewer limitations.

    There should be lots of samples in the CodeBank and on the Web.

  3. #3

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    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


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    What do you mean by "image" though?

    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.

  5. #5

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    thanlks, am sending a jpg file
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    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.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    thatns, but this dosent work for me, i need to send this as a string instead
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Send image betweeb two apps using IPC

    You can send image data as a string using Winsock


    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.

  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    Quote Originally Posted by coolcurrent4u View Post
    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?

  10. #10

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    i will be converting the image to bytes array, then convert to hex string, send to the interested app, then reverse the process there.
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Send image betweeb two apps using IPC

    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.

  12. #12
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: Send image betweeb two apps using IPC

    what is a uses of propertybag in your code ?
    Code:
    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.

  13. #13

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    i tried sending data between the two apps, the length (len(data))is 60K, i get an error see the attached pics
    Attached Images Attached Images  
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  14. #14
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    Quote Originally Posted by firoz.raj View Post
    what is a uses of propertybad in your code ?
    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?

  15. #15

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    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


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  16. #16
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Send image betweeb two apps using IPC

    That's pretty simple. You should be able to work it out from the example I posted, or the thousands of other examples out there, or the VB manual.

  17. #17

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    can you point me to any or give me keywords to search
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  18. #18
    Addicted Member
    Join Date
    Nov 2006
    Posts
    129

    Re: Send image betweeb two apps using IPC

    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)

  19. #19
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Send image betweeb two apps using IPC

    Quote Originally Posted by coolcurrent4u View Post
    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)

  20. #20

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    Dilettante's code is using winsock, what am trying to do is IPC
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  21. #21
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Send image betweeb two apps using IPC

    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.

    What do you mean by IPC?
    Last edited by Doogle; Sep 1st, 2012 at 03:05 AM.

  22. #22

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Send image betweeb two apps using IPC

    Winsock is one method, of many, that can be used to implement IPC.
    yes i know, but the other app is delphi and i choose IPC for simplicity communicate via only IPC
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  23. #23
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Send image betweeb two apps using IPC

    Quote Originally Posted by coolcurrent4u View Post
    but the other app is delphi
    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.
    Last edited by Doogle; Sep 1st, 2012 at 05:06 AM.

  24. #24

    Thread Starter
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: [RESOLVED] Send image betweeb two apps using IPC

    thanks all for your help, i figured another way out
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width