[Mono-list] va_list in DllImport

Paolo Molaro lupus@ximian.com
Sun, 30 Jun 2002 19:13:20 +0200


On 06/25/02 Dietmar Maurer wrote:
> On Tue, 2002-06-25 at 08:23, Rachel Hestilow wrote:
> > If I wanted to DllImport a function that accepted a va_list parameter
> > (function gnome_program_initv, in this case), how would I express that
> > parameter in C#? The only comparable construct in C# would seem to be
> > object[], but I'm not sure if that provides enough information for the
> > runtime to marshal everything correctly.
> > 
> > Alternately, does DllImport support marshalling varargs functions
> > directly? (so I could use gnome_program_init instead of
> > gnome_program_initv). Either one would work for my purposes.
> 
> C# has vararg support: see mono/mono/tests/vararg.cs. But I am not sure
> if that works with DllImport an it is currently not supported by mono.

vararg is different from va_list support, though, so it would not help
anyway. I didn't find mention anywhere about va_list support for
P/Invoke (it's highly compiler-specific). Basically, the va_list
variants are completely useless unless you are in C code.

The issue is usually solved with overloading:

	[Dll(...)]
	IntPtr gnome_program_init(string app_id,..., string first_property, string first_val, IntPtr term_null);
	[Dll(...)]
	IntPtr gnome_program_init(string app_id,..., string first_property, int first_val, IntPtr term_null);

and calling it with:
	gnome_program_init("myprog", ..., "app-prefix", "/blh/blah", IntPtr.Zero);
etc.

In the specific case, since gnome_program_init() is an helper method, I
suggest working around it and calling the gnomelib_preinit() etc
functions instead.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better