UPDATE: Found a handy C# project template that does this with less fuss (it uses Cecil btw unlike the other solutions):
http://sites.google.com/site/robertgiesecke/
EDIT: I was looking for a tool to automate this but the one I found didn't work so I posted hopefully better one below. This is useful with countless popular proprietary win32 apps that only support calling straight C DLL's. As it's not really supported in C# AFAIK it may not be wise to use on widely distributed dll's.
This article explains it's possible to hack C# dll so it can be called directly from native code. There's probably some reason why it's not supported directly without hacks but well if it works then that's fine.
http://wayback.archive.org/web/20081015000000*/http://www.csharphelp.com/archives3/archive500.html
But editing the IL after every compile isn't fun and if I create a dll that I don't edit well that makes the whole exercise pointless, I might as well used CLI wrapper then. I find that tends to complicate things and slow down the rapid first development iteration. I'm not sure yet if this is better or worse when it comes to later maintenance and debugging - it's probably best to keep the ilasm,ildasm,fusion.dll and this tool with the project that uses it and write a note.
EDIT2:
There's an interesting attribute in NET 3.5->
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
However it doesn't do much according to quote ref source quote I found in SO.
// To be used on methods that sink reverse P/Invoke calls.
// This attribute is a CoreCLR-only security measure, currently ignored by the desktop CLR.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class AllowReversePInvokeCallsAttribute : Attribute
{
public AllowReversePInvokeCallsAttribute()
{
}
}
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.