Passing Memory Stream between C# Windows

capri

Active member
Joined
Jun 16, 2015
Messages
42
Programming Experience
5-10
Hi,


I'd like to know if it's possible to pass memory stream between C# windows.


Thanks
 
This is the code to send stream. But it doesn't really work.
using (MemoryStream ms = GetMemoryStream())
{
    int hWnd = FindWindow(null, "Receive");
    int dataSize = Convert.ToInt32(ms.Length);

    COPYDATASTRUCT cds;
    cds.dwData = 0;
    cds.lpData = Marshal.AllocCoTaskMem(dataSize);
    cds.cbData = dataSize;

    SendMessage(hWnd, WM_COPYDATA, 0, ref cds);

    Marshal.FreeCoTaskMem(cds.lpData);
}
 
Last edited:
I'm trying to send memory stream of a pdf file from one c# application to another. The GetMemoryStream takes the pdf file and converts it into a memory stream. The receiving application should take the memory stream and convert it back to a pdf file.
 
It is between two applications. Both are C# Winforms.

I get an error is at


int dataSize = Convert.ToInt32(ms.Length);


and the error is "Cannot access a closed Stream."
 
Back
Top Bottom