[Gtk-sharp-list] Wrapping Tool?

Miguel de Icaza miguel@ximian.com
04 Mar 2003 16:10:15 -0500


Hello,

> What we need is something that can "preprocess" files, and
> change C types to the appropriate C# type for that system.
> 
> Maybe, have code like:
> 
>     @C_TYPE(time_t)@ time;
> 
> And the preprocessor would change this to:
> 
>     System.Int32 time;
> 
> (Or whatever is appropriate for the system.)

The problem with this approach is that your assemblies will not be
portable between systems with different sizes for time_t.  In these
cases, the best thing to do is to write some C glue code, and use the
largest possible value (8-byte long) and expose that to the C# code.

Another option is to have runtime detection of the size of this
structure, and pick the right method based on that:

	[DllImport ("",EntryPoint=time)]
	int int_time (int *p);

	[DllImport ("", EntryPoint=time)]
	long long_time (long *p);

And call the appropriate function.

Miguel