private MemoryStream SaveIconCursorToStream(byte[] buffer, bool isCursor) { MemoryStream memoryStream = new MemoryStream(); IntPtr hIcon = User32.CreateIconFromResource(buffer, isCursor); if (hIcon == IntPtr.Zero) { throw new ExternalException("Native call API failed (CreateIconFromResource)"); } using (Icon icon = Icon.FromHandle(hIcon)) { icon.Save(memoryStream); } // return(memoryStream); }