471,122 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

HOWTO: use ArgIterator

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
Nov 22 '05 #1
3 2007
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2
Mattias Sjögren wrote:
[...]
static void Varargs(__arglist)
[...]


<shudder>
Nov 22 '05 #3
Hello, Mattias!
You wrote on Fri, 05 Mar 2004 20:35:40 +0100:

>> I haven't found any example of using ArgIterator and
>> RuntimeArgumentHandle in MSDN. Are they analogous to elipsis
>> (...) in C++?


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
Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.