[Mono-winforms-list] swf patch

Aleksey Ryabchuk ryabchuk@yahoo.com
Thu, 27 Mar 2003 04:16:24 -0800 (PST)


--0-955266601-1048767384=:10153
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

Hello Alexandre,

> Mono doesn't implement Marshal.AllocCoTaskMem and
> applications crash under Linux.
> So, I commented few lines in tooltip.cs for a
> moment.

In this case I think we'd be better off using
Marshal.AllocHGlobal instead of AllocCoTaskMem. It's
implemented in Mono. I've attached the patch that
fixes this. It also contains bug-fix for DTP control.
Hope it will work on Linux.

DateTimePicker.cs,
StatusBar.cs,
tooltip.cs : Fixed AllocCoTaskMem issue. Bug-fix for
DTP.

Regards
Aleksey


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
--0-955266601-1048767384=:10153
Content-Type: text/plain; name=patch
Content-Description: patch
Content-Disposition: inline; filename=patch

Index: DateTimePicker.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/DateTimePicker.cs,v
retrieving revision 1.11
diff -u -r1.11 DateTimePicker.cs
--- DateTimePicker.cs	24 Mar 2003 23:28:11 -0000	1.11
+++ DateTimePicker.cs	27 Mar 2003 11:58:43 -0000
@@ -163,7 +163,7 @@
 
 		protected override void OnHandleCreated(EventArgs e) {
 			base.OnHandleCreated(e);
-			setControlRange( (int)( DateTimePickerFlags.GDTR_MIN | DateTimePickerFlags.GDTR_MAX ) );
+			setControlRange( );
 			setControlValue( );
 			setCalendarColors( );
 			setCustomFormat( );
@@ -356,7 +356,7 @@
 						string.Format ("DateTimePicker does not support dates after {0}.", MaxDateTime ) );
 
 				maxDate = value;
-				setControlRange	( (int)DateTimePickerFlags.GDTR_MAX );
+				setControlRange	( );
 			}
 		}
 
@@ -375,7 +375,7 @@
 					string.Format ("DateTimePicker does not support dates before {0}.", MinDateTime ) );
 
 				minDate = value;
-				setControlRange	( (int)DateTimePickerFlags.GDTR_MIN );
+				setControlRange	( );
 			}
 		}
 
@@ -505,11 +505,11 @@
 			if ( IsHandleCreated ) 	{
 				SYSTIME systime = toSysTime ( val ) ;
 
-				IntPtr ptr = Marshal.AllocCoTaskMem ( Marshal.SizeOf ( systime ) );
+				IntPtr ptr = Marshal.AllocHGlobal ( Marshal.SizeOf ( systime ) );
 				Marshal.StructureToPtr( systime, ptr, false );
 				Win32.SendMessage ( Handle, (int)DateTimePickerMessages.DTM_SETSYSTEMTIME,
 							(int)DateTimePickerFlags.GDT_VALID, ptr );
-				Marshal.FreeCoTaskMem( ptr );
+				Marshal.FreeHGlobal ( ptr );
 			}
 		}
 
@@ -527,7 +527,7 @@
 		private void getControlValue ( bool updateProp ) {
 			if ( IsHandleCreated ) 	{
 				SYSTIME systime = new SYSTIME();
-				IntPtr ptr = Marshal.AllocCoTaskMem ( Marshal.SizeOf ( systime ) );
+				IntPtr ptr = Marshal.AllocHGlobal ( Marshal.SizeOf ( systime ) );
 				Marshal.StructureToPtr( systime, ptr, false );
 				int res = Win32.SendMessage ( Handle, (int)DateTimePickerMessages.DTM_GETSYSTEMTIME,
 							      0	, ptr ).ToInt32();
@@ -542,20 +542,22 @@
 				}
 				else
 					CHecked = false;
-				Marshal.FreeCoTaskMem( ptr );
+				Marshal.FreeHGlobal ( ptr );
 			}
 		}
 
-		private void setControlRange ( int rangeFlag ) {
+		private void setControlRange (  ) {
 			if ( IsHandleCreated ) {
 				SYSTIME[] range = { toSysTime ( MinDate ), toSysTime ( MaxDate ) };
-				IntPtr buffer = Marshal.AllocCoTaskMem( Marshal.SizeOf( range[0] ) * 2 );
+				IntPtr buffer = Marshal.AllocHGlobal ( Marshal.SizeOf( range[0] ) * 2 );
 				IntPtr current = buffer;
 				Marshal.StructureToPtr ( range[0], current, false );
 				current = (IntPtr)( current.ToInt32() + Marshal.SizeOf( range[0] ) );
 				Marshal.StructureToPtr ( range[1], current, false );
-				Win32.SendMessage( Handle, (int)DateTimePickerMessages.DTM_SETRANGE, rangeFlag, buffer.ToInt32() );
-				Marshal.FreeCoTaskMem( buffer );
+				Win32.SendMessage( Handle, (int)DateTimePickerMessages.DTM_SETRANGE,
+							(int)( DateTimePickerFlags.GDTR_MIN | DateTimePickerFlags.GDTR_MAX ),
+							 buffer.ToInt32() );
+				Marshal.FreeHGlobal ( buffer );
 			}
 		}
 
Index: StatusBar.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/StatusBar.cs,v
retrieving revision 1.13
diff -u -r1.13 StatusBar.cs
--- StatusBar.cs	24 Mar 2003 23:28:11 -0000	1.13
+++ StatusBar.cs	27 Mar 2003 11:58:43 -0000
@@ -274,11 +274,11 @@
 				CalculatePanelWidths ( array );
 				int size = array.Length;
 
-				IntPtr buffer = Marshal.AllocCoTaskMem( Marshal.SizeOf( size ) * size );
+				IntPtr buffer = Marshal.AllocHGlobal ( Marshal.SizeOf( size ) * size );
 				Marshal.Copy( array, 0, buffer, size );
 				Win32.SendMessage( Handle, (int)StatusbarMessages.SB_SETPARTS, size, buffer.ToInt32() );
 				Win32.SendMessage( Handle, (int)StatusbarMessages.SB_SIMPLE, 0, 0 );
-				Marshal.FreeCoTaskMem( buffer );
+				Marshal.FreeHGlobal ( buffer );
 			}
 			else {
 				Win32.SendMessage( Handle, (int)StatusbarMessages.SB_SIMPLE, 1, 0 );
Index: tooltip.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/tooltip.cs,v
retrieving revision 1.8
diff -u -r1.8 tooltip.cs
--- tooltip.cs	26 Mar 2003 23:44:37 -0000	1.8
+++ tooltip.cs	27 Mar 2003 11:58:44 -0000
@@ -243,13 +243,10 @@
 
 		private void sendMessageHelper ( ToolTipControlMessages mes, ref TOOLINFO ti ) {
 			if ( tooltipWnd.Handle != IntPtr.Zero ) {
-/*
-// FIXME: AllocCoTaskMem is not implemented in Mono.
-				IntPtr ptr	= Marshal.AllocCoTaskMem ( Marshal.SizeOf ( ti ) );
+				IntPtr ptr	= Marshal.AllocHGlobal ( Marshal.SizeOf ( ti ) );
 				Marshal.StructureToPtr( ti, ptr, false );
 				Win32.SendMessage ( tooltipWnd.Handle ,	(int)mes, 0, ptr.ToInt32() );
-				Marshal.FreeCoTaskMem( ptr );
-*/
+				Marshal.FreeHGlobal ( ptr );
 			}
 		}
 	}

--0-955266601-1048767384=:10153--