In an attempt to get around a resource leak issue, I tried to serialize a
Cursor to a MemoryStream but the serialization fails with "Stock cursors
cannot be serialized." This is puzzling since the Cursor being serialized is
built from a bitmap and is not a stock cursor at all. Is this a misleading
error message or am I actually somehow really serializing a stock cursor.
Here's the code, pared down to its essentials.
public Cursor MakeCursor(Bitmap bm)
{
IntPtr ptr = bm.GetHicon();
Cursor retCursor = new Cursor(ptr);
BinaryFormatter f = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
// The following line throws an exception...
f.Serialize(ms, retCursor);
DestroyIcon(ptr);
return retCursor;
}
--
Richard Lewis Haggard
www.Haggard-And-Associates.com