delegate calling convention

  • Thread starter Thread starter apm
  • Start date Start date
A

apm

Is there a way to change the calling convention of a delegate to Cdecl? Is
it possible to define a callback function in C# that used the Cdecl
convention?

Thanks in advance.
 
apm,

You can only do this in .NET 2.0. You can apply the
UnmanagedFunctionPointer attribute to the delegate.

In .NET 1.1 and before, you would have to pass your delegate to an
unmanaged piece of code which has the signature of the delegate, and pass
that to your function.

Hope this helps.
 
Nicholas Paldino said:
apm,

You can only do this in .NET 2.0. You can apply the
UnmanagedFunctionPointer attribute to the delegate.

In .NET 1.1 and before, you would have to pass your delegate to an
unmanaged piece of code which has the signature of the delegate, and pass
that to your function.

Hope this helps.

Thank you. This is what I have done in the past using C++. Can it be done
with C#?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

apm said:
Is there a way to change the calling convention of a delegate to Cdecl?
Is it possible to define a callback function in C# that used the Cdecl
convention?

Thanks in advance.
 
No, not in v1.x. All you can do is change your C++ code's calling convention
to _stdcall (WINAPI), which is the default for callbacks in Win32. Another
option is to change and reassemble the IL in a post-build step.

Willy.


apm said:
Nicholas Paldino said:
apm,

You can only do this in .NET 2.0. You can apply the
UnmanagedFunctionPointer attribute to the delegate.

In .NET 1.1 and before, you would have to pass your delegate to an
unmanaged piece of code which has the signature of the delegate, and pass
that to your function.

Hope this helps.

Thank you. This is what I have done in the past using C++. Can it be
done with C#?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

apm said:
Is there a way to change the calling convention of a delegate to Cdecl?
Is it possible to define a callback function in C# that used the Cdecl
convention?

Thanks in advance.
 
Willy Denoyette said:
No, not in v1.x. All you can do is change your C++ code's calling
convention to _stdcall (WINAPI), which is the default for callbacks in
Win32.

I don't have the source.
Another option is to change and reassemble the IL in a post-build step.
Interesting.


Willy.

Thank you so much.
apm said:
Nicholas Paldino said:
apm,

You can only do this in .NET 2.0. You can apply the
UnmanagedFunctionPointer attribute to the delegate.

In .NET 1.1 and before, you would have to pass your delegate to an
unmanaged piece of code which has the signature of the delegate, and
pass that to your function.

Hope this helps.

Thank you. This is what I have done in the past using C++. Can it be
done with C#?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there a way to change the calling convention of a delegate to Cdecl?
Is it possible to define a callback function in C# that used the Cdecl
convention?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top