coapp-developers team mailing list archive
-
coapp-developers team
-
Mailing list archive
-
Message #00659
FYI: Exporting C functions from a .NET assembly so the loading app doesn't even know that it's a .NET assembly.
The managed version of the CoApp engine still needs to export C functions from the CoApp-Engine.dll Assembly.
No .NET language supports exporting C style functions from the assembly, yet .NET does, if you use ILASM and hand code it to do that. A couple years ago I built a tool to automatically do that using an Attribute (which I ever-so-cleverly called DllExport), and a command line tool to write the fixups.
The tool generates a .NET assembly that has the exports, and forwards the C call on to the managed static function.
By default, the tool takes a given .NET assembly (foo.dll) with functions marked with DllExport , it generates a companion assembly ($foo.dll). You can even debug straight from native to managed and back to native without doing anything special.
For a release build, the tool can merge the fixups right into the target DLL--so that foo.dll itself has the C functions exported.
It even supports callback functions (implemented as delegates in c#)
The tool is part of my gsToolkit I wrote: http://gstoolkit.codeplex.com/wikipage?title=DllExport&referringTitle=Home
public class CoAppEngine{
public delegate int ResolveCallback(string packageName, string localPath, string url);
[DllExport("coapp_resolve")]
public static int MyFunction(string packagePath, ResolveCallback callback) {
callback("foo", "bar", "http://foo");
return 0;
}
}
and you can see the results:
C:\root\projects\CoApp\output\any\debug\bin>dumpbin /exports $coapp-engine.dll
Dump of file $coapp-engine.dll
File Type: DLL
Section contains the following exports for $coapp-engine.dll
00000000 characteristics
4C780756 time date stamp Fri Aug 27 11:43:34 2010
0.00 version
0 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
0 0 0000227E coapp_resolve
[Description: fearthecowboy]<http://fearthecowboy.com/>
Garrett Serack | Microsoft's Open Source Software Developer | Microsoft Corporation
Office:(425)706-7939 email/messenger: garretts@xxxxxxxxxxxxx<mailto:garretts@xxxxxxxxxxxxx>
blog: http://fearthecowboy.com<http://fearthecowboy.com/> twitter: @fearthecowboy<http://twitter.com/fearthecowboy>
I don't make the software you use; I make the software you use better on Windows.