HOWTO: use ArgIterator

  • Thread starter Thread starter Vladimir
  • Start date Start date
V

Vladimir

Hello, All!

I haven't found any example of using ArgIterator and RuntimeArgumentHandle in MSDN. Are they analogous to elipsis (...) in C++? Can I call DLL exported function with elipsis using ArgIterator?

Regards,
Vladimir.

Winamp 5.0 (playing): Stratovarius - 4th Reich
 
Vladimir,
I haven't found any example of using ArgIterator and RuntimeArgumentHandle in MSDN. Are they analogous to elipsis (...) in C++?

Here's an example

static void Varargs(__arglist)
{
ArgIterator args = new ArgIterator( __arglist );

int argCount = args.GetRemainingCount();
for ( int i = 0; i < argCount; i++ )
Console.WriteLine( TypedReference.ToObject( args.GetNextArg() ) );
}

static void Main()
{
Varargs( __arglist( 123, 456.78, "abc" ) );
}

Can I call DLL exported function with elipsis using ArgIterator?

You only need ArgIterator if you want to implement a varargs method.
For calling one you only need __arglist. __arglist, BTW, is
undocumented so there's no guarantee that it'll work in future
versions or other C# compilers. For pure managed work I'd strongly
recommend using params instead.



Mattias
 
Hello, Mattias!
You wrote on Fri, 05 Mar 2004 20:35:40 +0100:


MS> Here's an example
MS> static void Varargs(__arglist)
MS> Varargs( __arglist( 123, 456.78, "abc" ) );

And what about RuntimeArgumentHandle?

Another question. If I have some exported function in DLL defined like this

_declspec(dllexport) void DummyFn(char *sz1, char sz2, ...)
{
va_list marker;
vs_start(marker, sz2);
<do_some_stuff>;
va_end(marker);
}

how can I call it from C#? I've tried __arglist and params. It doesn't work. It seems PInvoke doesn't support such calls. And IJW too.

Regards,
Vladimir.

Winamp 5.0 (playing): Stratovarius - Twilight Time
 
Back
Top