PC Review


Reply
Thread Tools Rate Thread

Calling Convension in .NET.,

 
 
=?Utf-8?B?QmFsYW11cmFsaSBD?=
Guest
Posts: n/a
 
      22nd Jun 2004
Hi all.,
I got some info from this iink
where u can find.,

Public Class LibWrap
' Visual Basic does not support varargs, so all arguments must be
' explicitly defined. CallingConvention.Cdecl must be used since the stack
' is cleaned up by the caller.
' int printf( const char *format [, argument]... )
<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, d As Double) As Integer
End Function
<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, s As String) As Integer
End Function
End Class 'LibWrap
Public Class App
Public Shared Sub Main()
LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99,
99.99)
LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, _
"abcd")
End Sub 'Main
End Class 'App

if VB.NET does't support VarArgs then how come
Console.Write("Test{0}{1}..",3,4) is works?


Regards Balamurali C
 
Reply With Quote
 
 
 
 
Richard Grimes [MVP]
Guest
Posts: n/a
 
      22nd Jun 2004
"Balamurali C" <(E-Mail Removed)> wrote in message
news230CCD2-5282-494F-9DF4-(E-Mail Removed)...
> if VB.NET does't support VarArgs then how come
> Console.Write("Test{0}{1}..",3,4) is works?


There are lots of overloads of Write: one takes one object, another takes
two and another three (other than the format string). Take a look at an
example of this call in ILDASM, C# and VB.NET call this method:

call void [mscorlib]System.Console::Write(string, object, object)

now try this:

Console.Write("Test{0}{1}{2}{3}",3,4,5,6)

If you look at ILDASM you'll see that the following method is called:

call void [mscorlib]System.Console::Write(string, object[])

The compile creates an array of the parameters to Write before calling the
method.

If you try to call this same line in managed C++ you'll see that it calls:

call vararg void [mscorlib]System.Console::Write(string, object, object,
object, object)

In other words, only C++ calls vararg methods, and C++ can only call them,
it cannot write them. To write a vararg method you have to use ILASM.

Richard
--
My email address (E-Mail Removed) is encrypted with ROT13 (see
www.rot13.com)



 
Reply With Quote
 
=?Utf-8?B?QmFsYW11cmFsaSBD?=
Guest
Posts: n/a
 
      23rd Jun 2004
hi Richard Grimes
Ya thanks for your reply. still i hve some queries.,
I asked some c# people they said we can use Param (nearly equl to this name) Object to get number of parameter & paramter values too.
this is conflicts me.,


and one more thing., is it good way or writting overload function code which take 1 to n paramter, where n is big number.

like
write(string,object);
write(string,object,object);
............
...........
write(string,object,object................);


"Richard Grimes [MVP]" wrote:

> "Balamurali C" <(E-Mail Removed)> wrote in message
> news230CCD2-5282-494F-9DF4-(E-Mail Removed)...
> > if VB.NET does't support VarArgs then how come
> > Console.Write("Test{0}{1}..",3,4) is works?

>
> There are lots of overloads of Write: one takes one object, another takes
> two and another three (other than the format string). Take a look at an
> example of this call in ILDASM, C# and VB.NET call this method:
>
> call void [mscorlib]System.Console::Write(string, object, object)
>
> now try this:
>
> Console.Write("Test{0}{1}{2}{3}",3,4,5,6)
>
> If you look at ILDASM you'll see that the following method is called:
>
> call void [mscorlib]System.Console::Write(string, object[])
>
> The compile creates an array of the parameters to Write before calling the
> method.
>
> If you try to call this same line in managed C++ you'll see that it calls:
>
> call vararg void [mscorlib]System.Console::Write(string, object, object,
> object, object)
>
> In other words, only C++ calls vararg methods, and C++ can only call them,
> it cannot write them. To write a vararg method you have to use ILASM.
>
> Richard
> --
> My email address (E-Mail Removed) is encrypted with ROT13 (see
> www.rot13.com)
>
>
>
>

 
Reply With Quote
 
Richard Grimes [MVP]
Guest
Posts: n/a
 
      23rd Jun 2004
> Ya thanks for your reply. still i hve some queries.,
> I asked some c# people they said we can use Param (nearly equl to this

name) Object to get number of parameter & paramter values too.
> this is conflicts me.,


Sorry, I wasn't clear in the reply. The version of Write that has an array
of objects is the one that uses the params keyword. The C# params keyword
has *nothing* to do with varargs, all it means is that there follows an
array of parameters and the method has the responsibility of reading the
parameters out of the array.

> and one more thing., is it good way or writting overload function code

which take 1 to n paramter, where n is big number.
>
> like
> write(string,object);
> write(string,object,object);
> ...........
> ..........
> write(string,object,object................);


Why not? You can write a single method that takes n parameters, and then the
other methods take 1 to n-1 parameters and just call the n parameter version
passing null in appropriate parameters. The methods with 1 to n-1 parameters
are just there for convenience and its a design decision as to which ones
are useful.

Richard
--
My email address (E-Mail Removed) is encrypted with ROT13 (see
www.rot13.com)


 
Reply With Quote
 
=?Utf-8?B?QmFsYW11cmFsaSBD?=
Guest
Posts: n/a
 
      23rd Jun 2004
Hi Richard Grimes very thx for ur reply.,
What might be the n value., as per microsoft definision.,

bcoz., supposing that can I give
let n = 1000
Console.write("{0}{1}..{n} ",1,2............n);

regards
Balamurali c


"Richard Grimes [MVP]" wrote:

> > Ya thanks for your reply. still i hve some queries.,
> > I asked some c# people they said we can use Param (nearly equl to this

> name) Object to get number of parameter & paramter values too.
> > this is conflicts me.,

>
> Sorry, I wasn't clear in the reply. The version of Write that has an array
> of objects is the one that uses the params keyword. The C# params keyword
> has *nothing* to do with varargs, all it means is that there follows an
> array of parameters and the method has the responsibility of reading the
> parameters out of the array.
>
> > and one more thing., is it good way or writting overload function code

> which take 1 to n paramter, where n is big number.
> >
> > like
> > write(string,object);
> > write(string,object,object);
> > ...........
> > ..........
> > write(string,object,object................);

>
> Why not? You can write a single method that takes n parameters, and then the
> other methods take 1 to n-1 parameters and just call the n parameter version
> passing null in appropriate parameters. The methods with 1 to n-1 parameters
> are just there for convenience and its a design decision as to which ones
> are useful.
>
> Richard
> --
> My email address (E-Mail Removed) is encrypted with ROT13 (see
> www.rot13.com)
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling SQL from code has different behaviour than calling it from MS SQL Server Management Studio jeeji Microsoft C# .NET 1 29th Jun 2006 10:43 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM
Fail to send fax when making international fax calling / calling c =?Utf-8?B?c2Ftd2lzZQ==?= Windows XP Help 1 28th Dec 2004 02:31 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= Microsoft ASP .NET 1 28th Sep 2004 01:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier Microsoft ASP .NET 4 29th Jul 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.