public static Win16.LOGBRUSH To16(Win32.LOGBRUSH lb32) { if (lb32.style == Win32.BS_DIBPATTERN) { throw new NotImplementedException("Unsupport log brush conversion BS_DIBPATTERN"); } return(new Win16.LOGBRUSH() { style = (ushort)lb32.style, color = lb32.color, hatch = (short)lb32.hatch, }); }
public short GetObject(HGDIOBJ hgdiobj, short cbBuffer, uint ptr) { unsafe { var objectType = GetObjectType(hgdiobj); switch (objectType) { case Win32.OBJ_PEN: { if (ptr == 0) { return((short)Marshal.SizeOf <Win16.LOGPEN>()); } // Check if buffer big enough if (cbBuffer < Marshal.SizeOf <Win16.LOGPEN>()) { return(0); } // Get it var lp32 = new Win32.LOGPEN(); var plp32 = &lp32; var size = GetObject(hgdiobj, Marshal.SizeOf <Win32.LOGPEN>(), (IntPtr)plp32); // Convert and write it back _machine.WriteStruct(ptr, Win32.LOGPEN.To16(lp32)); return((short)Marshal.SizeOf <Win16.LOGPEN>()); } case Win32.OBJ_BRUSH: { if (ptr == 0) { return((short)Marshal.SizeOf <Win16.LOGBRUSH>()); } if (cbBuffer < Marshal.SizeOf <Win16.LOGBRUSH>()) { return(0); } var lb32 = new Win32.LOGBRUSH(); var plb32 = &lb32; var size = GetObject(hgdiobj, Marshal.SizeOf <Win32.LOGBRUSH>(), (IntPtr)plb32); _machine.WriteStruct(ptr, Win32.LOGBRUSH.To16(lb32)); return((short)Marshal.SizeOf <Win16.LOGBRUSH>()); } case Win32.OBJ_BITMAP: { // Just asking for size? if (ptr == 0) { return((short)Marshal.SizeOf <Win16.BITMAP>()); } // Check if buffer big enough if (cbBuffer < Marshal.SizeOf <Win16.BITMAP>()) { return(0); } // Get it var bmp32 = new Win32.BITMAP(); var pbmp32 = &bmp32; var size = GetObject(hgdiobj, Marshal.SizeOf <Win32.BITMAP>(), (IntPtr)pbmp32); // Convert and write it back _machine.WriteStruct(ptr, Win32.BITMAP.To16(bmp32)); // Return size return((short)Marshal.SizeOf <Win16.BITMAP>()); } case Win32.OBJ_FONT: { // Just asking for size? if (ptr == 0) { return((short)Marshal.SizeOf <Win16.LOGFONT>()); } // Check if buffer big enough if (cbBuffer < Marshal.SizeOf <Win16.LOGFONT>()) { return(0); } // Get it var lf32 = new Win32.LOGFONT(); var size = GetObject(hgdiobj, Marshal.SizeOf <Win32.LOGFONT>(), out lf32); // Convert and write it back _machine.WriteStruct(ptr, Win32.LOGFONT.To16(lf32)); // Return size return((short)Marshal.SizeOf <Win16.LOGFONT>()); } default: throw new NotImplementedException("Unsupported object type passed to GetObject"); } } }