Can IronPython call .net dll directly? - c#

I am new to .net programming. I heard all .net supported languages can call .net dll even written by another .net supported languages. My question is that: Can IronPython call .net dll written by c# directly or easily under its command interpretation window?

Yes, you should be able to call any managed dll.
An example of how you would do that is detailed in https://stackoverflow.com/a/14210917/413672

Related

Classes in a DLL

I was using a DLL in C# and called a method which returned me a C# object of the DBConnection class. My question is, if the DLL don’t know which language it will be used on, how can it return an object of a C# class?
Not all DLLs are created equal. Some are COM-specific. Some are not. Some are .Net IL assemblies. Some are not. This DLL is a .Net assembly. The class objects it provides for your are not strictly C# objects. They are .Net objects.
This works out for you because C# is itself built for .Net, and uses .Net objects. If you were using VB.Net, F#, IronPython, C++CLR, or other platform that uses .Net, you'd also be able to use the DLL. But C, Java, VBA etc would have a much harder time.
The .NET assembly is a standard independent of language.
If you write a code in c# it will generate the same "assembly" .NET than VB .NET or F#.
The DLL does not return a "C# Object". The DLL return a .NET object.

It is possible to use BoxedApp SDK with powershell?

It is possible to load BoxedApp SDK dll with Powershell and use it?
Link to SDK: http://www.boxedapp.com/boxedappsdk/
This is not a managed .NET dll. This is native c++ (I think).
Yes, you can call C++ methods from PowerShell, although not directly. For this you need to use Platform Invoke (P/Invoke). Here are some articles you can start with:
http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/25/use-powershell-to-interact-with-the-windows-api-part-1.aspx
http://msdn.microsoft.com/en-us/library/eyzhw3s8.aspx
Also there are tools which generate C# code, which wraps C++ (like http://www.pinvoker.com/) that you can then use in your PowerShell scripts.
On the theorical point of view, it can be loaded.
PowerShell can use .NET code and .NET can use PINVOKE to load natives DLLs.
But are you sure you need to create such an intricate system ?

I have a c sharp dll. How can I make it usable in other languages, such as PHP or Delphi?

I have a dll developed in C Sharp. How can I make it usable in other languages, such as PHP or Delphi?
I cannot find any solution to this problem yet. Isn't there any easy way of doing this?
If Delphi can understand COM, then you can make a COM wrapper around the .NET DLL.
I am doing this now for an older IDE which doesn't understand .NET, but it understands COM so I am able to use the latest .NET features in my older applications.
In addition to COM, you could try these (from my Delphi Win32 to WCF answer) for Delphi Win32:
Use Delphi Prism with the UnmanagedExport attribute to create a .NET wrapper that you can call from native Delphi Win32
Use Managed VCL to do .NET interop from native Delphi Win32
From another Stackoverflow question: create a C++ DLL crossing the bridge this used "mixed mode C++"
Use RemObjects Hydra on both the C# or Delphi Prism and native Delphi Win32 side (RemObjects wrote Delphi Prism, so this works like a charm)
The last one might be the real one you are after.
For PHP it is a different story;
PHP might run on a non-Windows box,
there are .NET implementations of PHP that would allow for direct linking of your C# assembly DLL
--jeroen

Calling C# from native C++, without /clr or COM?

I have a class library written in C#, and I want to call it from a legacy native C++ application. The host application is truly native, compiled on Windows and Linux, and it’s a console application. So how can I make it call the C# class library, assuming using Microsoft .NET on Windows, and Mono on Linux?
I have looked at SWIG and wrapping with COM interfaces on Windows, but is there a standard recognized solution that works cross platform? I.e., that is generic, works with both Microsoft .NET and Mono. A write-once-use-everywhere implementation.
Solutions should expose the full class interfaces from the C# domain to the C++ domain.
Similar questions focus only on the Windows solutions, for example -
Call C# methods from C++ without using COM
If you want to do this cross platform, I would recommend going with a 100% Mono approach.
Mono has a clean Embedding API which works on Linux and Windows.
With .NET 5.0 (the successor of .NET Core) this is now possible to call C# from C++ in a cross-platform way without using Mono. Please see the solution explained in this GitHub issue using DNNE to generate a shared library and GCHandles to access C# objects.
With this you get a shared library that can be used from C or C++. Note that this will give a C-like API (no objects, like when using extern C in C++), in the future there may be tools like SWIG for C++ to overcome this limitation.

Import python functions into a .NET language?

I am a C# .NET programmer and am learning Python. I have downloaded IronPython, and know that it can call into .NET libraries.
I'm wondering whether there is a way to do the reverse, that is to call into some existing "classic" Python libraries in my C# code, maybe using .NET Interop.
I'd like to be able to access functions in libraries such as pygame.
Ironpython 2.0 is CPython 2.5 compatible, so pure Python that uses <=2.5 APIs should work fine under Ironpython. I believe Ironpython code can then be compiled into a DLL.
For C-extensions like Pygame, you might want to take a look at Ironclad. It's a project to allow for C-extensions to be used within Ironpython. This may also give you the native code bridge you're looking for.
You can use Python for .Net, which allows you to 'use CLR services and continue to use existing Python code and C-based extensions while maintaining native execution speeds for Python code.'
Further, 'A key goal for this project has been that Python for .NET should "work just the way you'd expect in Python", except for cases that are .NET specific (in which case the goal is to work "just the way you'd expect in C#"). In addition, with the IronPython project gaining traction, it is my goal that code written for IronPython run without modification under Python for .NET.'
Hope this helps

Categories