Changing calling convention of delegates in C# 2.0?

G

Guest

An oversight that affects me rather seriously in the current version of C# is the inability to change the calling convention of a delegate. The CLR supports it, and I have to resort to disassembling the assembly, hacking the source with a perl script, and reassembling it. This has the nasty side effect of preventing me from being able to step through or set breakpoints in my source code (the debugger then uses the MSIL instead)

Anyway, I know you can change the calling convention when doing DllImport, but when passing a function pointer to a native DLL, C# will only use the Windows calling convention for the delegate. Please fix this

It seems the fix would involve just adding a new attribute and having the compilers look for it. Will this be fixed in C#/.NET 2.0? If not, is there a reason why not? And for now, is there any better way to do this than the assembly hack? It's extremely painful to debug MSIL directly

Thank you
Adam M.
 
M

Morten Overgaard

I agree with you :)

I'm in the very same situation.

Another way of solve the issue is to create a managed C++ class which
receives the callback ( C++ does allow all calling conv. for delegates )
Make this class call back into your C# class either by a delegate or an
event.

I know this is not the optimal way - but it's better than the IL solution

Hope this helps :)

Regards Morten




AdamMil said:
An oversight that affects me rather seriously in the current version of C#
is the inability to change the calling convention of a delegate. The CLR
supports it, and I have to resort to disassembling the assembly, hacking the
source with a perl script, and reassembling it. This has the nasty side
effect of preventing me from being able to step through or set breakpoints
in my source code (the debugger then uses the MSIL instead).
Anyway, I know you can change the calling convention when doing DllImport,
but when passing a function pointer to a native DLL, C# will only use the
Windows calling convention for the delegate. Please fix this!
It seems the fix would involve just adding a new attribute and having the
compilers look for it. Will this be fixed in C#/.NET 2.0? If not, is there a
reason why not? And for now, is there any better way to do this than the
assembly hack? It's extremely painful to debug MSIL directly.
 
A

Ales Pour

+1

Ales Pour


AdamMil said:
An oversight that affects me rather seriously in the current version of C#
is the inability to change the calling convention of a delegate. The CLR
supports it, and I have to resort to disassembling the assembly, hacking the
source with a perl script, and reassembling it. This has the nasty side
effect of preventing me from being able to step through or set breakpoints
in my source code (the debugger then uses the MSIL instead).
Anyway, I know you can change the calling convention when doing DllImport,
but when passing a function pointer to a native DLL, C# will only use the
Windows calling convention for the delegate. Please fix this!
It seems the fix would involve just adding a new attribute and having the
compilers look for it. Will this be fixed in C#/.NET 2.0? If not, is there a
reason why not? And for now, is there any better way to do this than the
assembly hack? It's extremely painful to debug MSIL directly.
 

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

Top