none
How to transmit pictures from C# to VB6?

    Question

  • Hi everyone,

    I'm faced with the challenge of transmitting pictures as fast as possible from a C# WinForms application to a VB6 application. The pictures are generated one after the other, and only exist in memory as System.Drawing.Bitmap objects. "As fast as possible" - so that an acceptable degree of animation can be achieved. I am a little at a loss on how to go about it.
    On the C# end my guess would be to serialize the Bitmaps to a MemoryStream, pass the address of the stream to VB6, where it - hopefully - can be read. I'm investigating this latter issue too.
    Serializing a Bitmap object to a MemoryStream is not the problem, but
    - how do I find the address to pass to VB6?
    - how is VB6 to interpret the data in the stream so that I get the picture back (by for example using the VB6 PSet function)? In other words: what format does a serialized Bitmap object actually have?

    Is there a better approach?

    Any help will be greatly appreciated!

    Thanks in advance,
    Cooz

    Wednesday, April 26, 2017 7:34 AM

All replies

  • You cannot directly access the memory space of one process in Windows using another Process by simply passing a pointer (at least not with any version of Windows released in the last 20 years or so).
    What you need is called interprocess communications (IPC), and much of it is explained here:
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx
    I don't think there's an easy way to implement a high-performance solution that works with both C# and VB6, unless your fluent not only in the 2 languages, but also with Windows APIs (DllImport in C# and Declare Function in VB6). If you have this kind of experience, you could go for the Data Copy approach using Windows Messages:
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms648710(v=vs.85).aspx
    If you try this approach, look for the special considerations for Windows Vista and later versions.

    Another approach that can give you high performance in a much simpler way is to use multimedia streaming (video conferencing) to package the images as a video stream, send it from the first process and receive it in the second process. The 2 processes can even be running on 2 different computers connected through a network. You could use a library that has objects compatible with both C# and VB6 such as LEADTOOLS Multimedia (disclaimer: I work for this library's vendors).
    You can find more information here:
    https://www.leadtools.com/sdk/multimedia/video-conferencing

    Thursday, May 4, 2017 10:51 PM
  • The send and receive part is easy. Either named pipes, TCP/IP connection or CopyData suggested by Amin Dodin will do. (Actually CopyData is not preferred I'd say, because the C# side has to pin the memory, and does not know when to release it. The memory usage can accumulate quickly when sending image in fast rate)

    However, to process image without disk access you'll need to find components that allow reading in-memory file and display it. Most probably you'll need to find 3rd party components. (I've briefly searched and found a few the claims to be able to do so, but cannot verify the validity or whether they're safe to use so will not name them)




    Friday, May 5, 2017 1:39 AM
    Answerer