Create C# objects from C++

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Create C# objects from C++

howard.rubin
Some of the APIs I'm calling from C++ take C# objects, like
System.Drawing.PointF and System.IO.UnmanagedMemoryStream . I can create
them like below but I'd like to eliminate the hard coded paths to the .NET
DLLs.

Is it possible to reference the already loaded assembly or find the path to
the on-disk assembly or create the objects differently? How can I do that?


MonoAssembly* DrawingAssembly = mono_domain_assembly_open(domono.domain,
"*/usr/lib/mono/4.5/*System.Drawing.dll");
MonoImage* DrawingImage = mono_assembly_get_image(DrawingAssembly);
MonoClass* ptFClass = mono_class_from_name(DrawingImage, "System.Drawing",
"PointF");
etc.

OR

MonoAssembly* MscorlibAssembly = mono_domain_assembly_open(domono.domain,
"*/usr/lib/mono/4.5/*mscorlib.dll");
MonoImage* MscorlibImage = mono_assembly_get_image(MscorlibAssembly);
MonoClass* umsClass = mono_class_from_name(MscorlibImage, "System.IO",
"UnmanagedMemoryStream");
etc.



--
View this message in context: http://mono.1490590.n4.nabble.com/Create-C-objects-from-C-tp4670261.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create C# objects from C++

J Decker
with C++ you can use managed extensions and compile with /CLR /CLI?
https://msdn.microsoft.com/en-us/library/ms235635.aspx

But I don't know that that applies for mono.....
http://stackoverflow.com/questions/183377/does-mono-net-support-and-compile-c-cli
And apparently it doesn't

On Wed, Mar 15, 2017 at 1:56 PM, howard.rubin <[hidden email]> wrote:
Some of the APIs I'm calling from C++ take C# objects, like
System.Drawing.PointF and System.IO.UnmanagedMemoryStream . I can create
them like below but I'd like to eliminate the hard coded paths to the .NET
DLLs.

Is it possible to reference the already loaded assembly or find the path to
the on-disk assembly or create the objects differently? How can I do that?


MonoAssembly* DrawingAssembly = mono_domain_assembly_open(domono.domain,
"*/usr/lib/mono/4.5/*System.Drawing.dll");
MonoImage* DrawingImage = mono_assembly_get_image(DrawingAssembly);
MonoClass* ptFClass = mono_class_from_name(DrawingImage, "System.Drawing",
"PointF");
etc.

OR

MonoAssembly* MscorlibAssembly = mono_domain_assembly_open(domono.domain,
"*/usr/lib/mono/4.5/*mscorlib.dll");
MonoImage* MscorlibImage = mono_assembly_get_image(MscorlibAssembly);
MonoClass* umsClass = mono_class_from_name(MscorlibImage, "System.IO",
"UnmanagedMemoryStream");
etc.



--
View this message in context: http://mono.1490590.n4.nabble.com/Create-C-objects-from-C-tp4670261.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list


_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Create C# objects from C++

Robert Jordan
In reply to this post by howard.rubin
On 15.03.2017 21:56, howard.rubin wrote:
> Some of the APIs I'm calling from C++ take C# objects, like
> System.Drawing.PointF and System.IO.UnmanagedMemoryStream . I can create
> them like below but I'd like to eliminate the hard coded paths to the .NET
> DLLs.
>
> Is it possible to reference the already loaded assembly or find the path to
> the on-disk assembly or create the objects differently? How can I do that?


Use the mono_assembly_load APIs. Either those which take a
MonoAssemblyName argument or mono_assembly_load_with_partial_name
which takes an (partial) assembly name specified by a string.

You may want to look up "assembly name" on MSDN. E.g, the
shortest assembly name of System.Drawing.dll is

"System.Drawing"

which you can pass to mono_assembly_load_with_partial_name (),
and call it a day.

Robert


_______________________________________________
Mono-devel-list mailing list
[hidden email]
http://lists.dot.net/mailman/listinfo/mono-devel-list
Loading...