Discussion:
calling conventions C#
(too old to reply)
xcal
2009-09-26 16:11:34 UTC
Permalink
Hi group,

Only I want to do an experiment.
I tried to make a library in native C code,
and then using pinvoke,on C#,
such that altering calling conventions
everywhere as possible I could be able to do this

// function on native C code:
int f(int a,int b)
{
return a-b;
}

but using this by using pinvoke on C#
I want to obtain e.g.

f(2,0) = -2

is this possible ?, or I have a misconcept
about what calling conventions can control?
Perhaps not with C# I shall accomplish my goal,
but perhaps with some other language.

thanks very much in advance
Carlos.
MarkusSchaber
2009-09-28 06:29:11 UTC
Permalink
Hi, "xcal",
Post by xcal
Only I want to do an experiment.
I tried to make a library in native C code,
and then using pinvoke,on C#,
such that altering calling conventions
everywhere as possible I could be able to do this
  int f(int a,int b)
 {
     return a-b;
 }
but using this by using pinvoke on C#
I want to obtain e.g.
  f(2,0) = -2
is this possible ?, or I have a misconcept
about what calling conventions can control?
Perhaps not with C# I shall accomplish my goal,
but perhaps with some other language.
If you read the Thread about "Stack imbalance"
http://groups.google.com/group/microsoft.public.dotnet.framework.interop/browse_frm/thread/017b00ac83ce4209#
including the links given there, you see how dangerous it is what you
try to do. I would strongly advise do avoid anything of this in piece
of code which could come even close to production!

But if you really want to experiment, it seems that watcom has the
right tool for you: http://www.openwatcom.org/index.php/Calling_Conventions#Specifying_Calling_Conventions_the_Watcom_Way
xcal
2009-09-28 14:15:48 UTC
Permalink
hi Markus

thanks for your the good links,
I was trying only to learn a bit more
about calling conventions, I have no
other pourposes.

thanks,
Carlos

"MarkusSchaber" <***@soloplan.de> escribi� en el mensaje news:deee08aa-8891-469a-8a3c-***@n2g2000vba.googlegroups.com...
Hi, "xcal",
Post by xcal
Only I want to do an experiment.
I tried to make a library in native C code,
and then using pinvoke,on C#,
such that altering calling conventions
everywhere as possible I could be able to do this
int f(int a,int b)
{
return a-b;
}
but using this by using pinvoke on C#
I want to obtain e.g.
f(2,0) = -2
is this possible ?, or I have a misconcept
about what calling conventions can control?
Perhaps not with C# I shall accomplish my goal,
but perhaps with some other language.
If you read the Thread about "Stack imbalance"
http://groups.google.com/group/microsoft.public.dotnet.framework.interop/browse_frm/thread/017b00ac83ce4209#
including the links given there, you see how dangerous it is what you
try to do. I would strongly advise do avoid anything of this in piece
of code which could come even close to production!

But if you really want to experiment, it seems that watcom has the
right tool for you:
http://www.openwatcom.org/index.php/Calling_Conventions#Specifying_Calling_Conventions_the_Watcom_Way
Continue reading on narkive:
Loading...