-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COM/OO Interop #23
Comments
@mterwoord That is a good question. It does support marshalling
Yep. The /cc @jkotas |
I tried exporting a method taking a COM interface as argument, but then the build says |
@mterwoord The current marshalling of types in DNNE is non-existent so only primitive types are supported - DNNE doesn't support blittable structs or One of the goals of this project was to ensure cross-platform support. Since
The approach therefore would be expose native APIs with C friendly data types, do all the marshalling manually, and then call the actual .NET API. An example using public class NativeExports
{
[UnmanagedCallersOnly]
public static int StringLength(IntPtr strUtf8)
{
if (strUtf8 == IntPtr.Zero)
return -1;
var str = Marshal.PtrToStringUTF8(strUtf8);
return str.Length;
}
} |
My use case is a legacy system (Delphi 6 based) calling into .NET. Do you have any pointers to get |
@mterwoord SharpGenTools is a great option for generating this code. It doesn't provide the native exports though. Getting SharpGenTools and DNNE to share types shouldn't be too hard, but the signature requirements would remain (i.e. I work with @jkoritzinsky who has been maintaining the SharpGenTools project. Perhaps he has some ideas on how to integrate them efficiently. |
how would marshalling work? I thought that UnmanagedCallersOnly requires all method params to be blittable... |
For SharpGenTools usage with DNNE, you'd need to write a small stub that does some manual marshalling at any API boundaries that you want DNNE to export. SharpGenTools only generates code that consumes COM, it doesn't support automatically producing new entry points (and also the native->managed direction still could use some additional work). |
Following up on this. I got COM marshalling working, I just needed to export the methods with parameter type Now the only thing left for me to get working, before this really gets useful to me, is self-contained deployment. |
@mterwoord Yep. Manual marshalling is the best way given DNNE is primarily focused on only exposing exports. What is nice at this point is you can decide what way is most beneficial to you. Using the above APIs you are leveraging the built-in system, but you could also decide in the future to use SharpGenTools or some other tooling.
This is still of interest. We know how it can be done but simply need enough customer feedback to support it. The DNNE tooling is design to be an add on to .NET and will consume any features that become available to improve its UX. I would file an issue on the dotnet/runtime repo asking about self-contained libraries. The people to tag are @vitek-karas and @agocke. |
@AaronRobinsonMSFT Thanks for answering during holiday season! I Kind-of got things working. If I put a runtime folder structure in my folder, and include the correct stuff there, things just work. Not completely "self-contained" as it involves manual code and some manual loading steps, but works well enough for me. (Of course, out of the box self-contained support would still be preferred) |
@mterwoord Just curious about your scenario: We currently don't support multiple CoreCLR runtimes in one process, that's why general self-contained support for libraries (we call these scenarios components sometimes as well) is not available (since if a process would load two self-contained libraries, it would need to load two runtimes -> unsupported). It would work only if you could somehow guarantee that the native process will only ever load your one library which uses .NET Core. As @AaronRobinsonMSFT mentions above, this is mostly about customer demand - if it turns out it's relatively common to have exactly one .NET Core component in a process, then the lack of SxS runtimes doesn't matter. |
My situation is having a handful of Delphi 6 legacy apps, which are extended using 1 (set of) .net libraries. This is 1 .net environment, not multiple. |
@mterwoord I am going to close this issue as I've finally gotten around to adding a simple example for how to do this: https://github.com/AaronRobinsonMSFT/DNNE/blob/master/test/ExportingAssembly/InstanceExports.cs. I think there is an opportunity to fully automate this process using a Roslyn source generator but I don't think that is in scope for this specific project. |
Thanks for the demo! |
Does .NET Core support COM marshalling of objects passed around?
In .NET 4.7, one can use https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports to call methods and then return (and pass in) pointers to objects, which are callable from both sides, using COM marshalling.
The text was updated successfully, but these errors were encountered: