Hi, I need to get bytes from HICON handle to send it from server(C++) to client(C#) but I do not know how.
i need to send the byte with
send(socket,(CHAR*)&Byte_to_send,sizeof(Byte_to_send);
Byte_to_send should be the bytes associated to HICON of each windows application, and
I've got it in this way:
HICON icon = (HICON)GetClassLong(hWnd, GCL_HICON);
What I have tried:
SIDE C++ SERVER:
HICON icon = (HICON)GetClassLong(hWnd, GCL_HICON);
ICONINFO oIconInfo;
if(::GetIconInfo(icon, &oIconInfo)==true){
cout <<"Success!"<<endl;
send(newConnection,(CHAR*)&oIconInfo,sizeof(oIconInfo),NULL);
}else{
cout <<"Failure!"<<endl;
}
Now I have to convert the stream of byte read from my client(this is made in c#) that I have received from my c++ server, and convert the array of bytes to an Image.
So I have tried to do this:
SIDE C# CLIENT:
byte[] buffer = new byte[1500];
sck.Receive(buffer);
TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(buffer);
imageList1.Images.Add(bitmap1);
When I try this, I receive an error at this line:
Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(buffer);
This is the message error that I have received:
Unhandled exception of the 'System.ArgumentException' type System.Drawing.dll
Additional information: Invalid parameter.
I have also tried:
MemoryStream ms = new MemoryStream(buffer);
Bitmap bmp;
bmp = new Bitmap(ms);
and this other:
ImageConverter ic = new ImageConverter();
System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(buffer);
Bitmap bitmap1 = new Bitmap(img);
but I have received the same error message.