Sunshine

Sunshine

  • NA
  • 201
  • 26.7k

How do I use SendMessage to send a memory stream?

Jul 8 2016 2:32 AM
Hi,

I'm trying to use the SendMessage for sending memory stream. I did some code, but not working. Here's my code.
 
 
stream.Seek(0, SeekOrigin.Begin); 
int dataSize = Convert.ToInt32(stream.Length);                 
byte[] byteArray = new byte[dataSize];                 
int count = stream.Read(byteArray, 0, 20);                                  
while(count < stream.Length)                 
{                     
byteArray[count++] = Convert.ToByte(stream.ReadByte());                 
}                   
IntPtr ptrData = Marshal.AllocCoTaskMem(dataSize);                 
Marshal.Copy(byteArray, 0, ptrData, dataSize);                   
CopyDataStruct cds = new CopyDataStruct                 
{               
cbData = dataSize,                   
dwData = (IntPtr)1,                   
lpData = ptrData                 
};                                    
 SendMessage(hWnd, WM_COPYDATA, 0, cds);

Thanks