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 ?
Related
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
I stumbled upon a tool that generates P/Invoke signatures for Microsoft's own unmanaged DLLs: PInvoke Interop Assistant
Is there a similar tool that will generate P/Invoke signatures for third-party unmanaged DLLs?
Alternately, any way to feed a third-party DLL to PInvoke Interop Assistant
EDIT: Actual issue I am trying to resolve
Google quickly found http://www.pinvoker.com (Wayback) (Compatiblity listed as VS2005, 2008, and 2010; it doesn't seem to have been updated to work with newer versions)
Microsoft's C++/CLI compiler can also do this, if you use /clr:safe and #include the header file, it will generate p/invoke code which you can extract with e.g. ILSpy (free) or Red Gate Reflector (used to be free).
I use PInvoke Interop Assistant for unmanaged DLLs by using the third tab in the UI, marked "SigImp Translate Snippet". Simply copy-and-paste your header into the "Native Code Snippet" window and press Generate (or turn on Auto Generate). As an illustration here's some code from a question of mine. Note that for some reason errors don't appear in the Error panel but as comments at the top of the generated code.
As several people have already said, the generated code should be used as a guide - you may well have to make changes to get exactly what you want.
This project is active and looks promising for the task: https://github.com/mono/CppSharp
You can create C# wrapper for any native DLL including both C-style DLL exporting functions and C++ DLL exporting classes by using xInterop C++ .NET Bridge with .NET to Native C++ Bridge. It is available for free evaluation with some limitations.
Disclaimer: I am the author of xInterop C++ .NET Bridge.
Another alternative is the SharpGenTools. It is used by SharpDX to "automatically" create bindings of the directx api.
There's also CppSharp, it's used by QtSharp to generate bindings to native C++/C libs. Until now CppSharp is only compatible with .Net Framework 6+.
I use ClangSharp open-source tool. It is command line app that has plenty of settings to customize the output. Windows and Linux are supported.
Use Dumpbin.exe that comes with the VS SDK,
Dumpbin, you'll still need to write the pinvoke signatures manually from the dumped data
When I try to use LuaInterface on Mono on Linux (using Mono 2.0 on Ubuntu 9.04) I get the following exception:
** (App.exe:8599): WARNING **: Method ':.DoDllLanguageSupportValidation ()' in assembly
'/home/ulrich/test/Debug/lua51.dll' contains native code that cannot
be executed by Mono on this platform.
The assembly was probably created using C++/CLI.
According to this web site LuaInterface can be used with Mono. MoMA says that too.
Is it possible to recompile lua51.dll to make it compatible to Mono?
LuaInterface looks to be pure C#, but it uses a mixed mode C++/CLI-ified version of the Windows version of the native Lua library, that mixes .NEt code and native 32-bit Windows code. There's no C++/CLI compiler for platforms other than Windows, so you can't port/recompile the C++/CLI code, though it should work on Mono on Win32 (or maybe Wine)..
The only really viable way to get this to work on Mono would be to make it use P/Invokes istead of C++/CLI. You could then use a dllmap so that when Mono tries to resolve the P/Invoke calls to lua51.dll, it is redirected to the Linux equivalent, liblua.so.5.1.
Older versions of LuaInterface use a pure P/Invoke wrapper. You could use this.
There are also a few attempts at alternatives, my own included. http://github.com/jsimmons/LuaSharp
For all of you reading this now: Use KopiLuaInterface!
See my post here: https://stackoverflow.com/a/21386450/1070906
I have the source code of a C# program. I want to create a DLL out of it which I want to use in C++.
Is it possible to create a native DLL in Visual Studio 2008 which can be used in C++?
native <-> .Net interop is one of my pet disciplines, which is why I needed this as straightforward and reliable as possible.
The result was that I made me an MSBuild task which I just need to drag into a project to allow me to export static methods from pretty much any .Net language. And since the whole marshalling infrastructure works for exports as well, you can do pretty much anything with it that you want (like passing native/managed objects as IUnknown).
The resulting assembly will look to the consuming process like a real DLL, which means you can't have it to scale up to 64bit automatically anymore.
However, since you do have native bits in your application, you already have this issue anyways. ;-)
When you do not specifiy the CPU target in your C# project, my task will emit a warning that it created a folder for all targets (x86,x64 and Itanium), and there you'll have *.dll and *.pdb for each platform.
If you want the program to be native, and not managed, you'll need to port it to C++, instead of using C#.
That being said, you can compile it in C# into a library, and use it from C++ by using C++/CLI. This just requires that you compile the files that use the C# library with the /clr flag. This provides C++ access to the .NET framework, and lets you use libraries made in C# directly from C++.
Alternatively, you can use .NET's COM interop to expose the C# class(es) as COM objects, and then use those from native C++.
It is possible in Visual Studio 2008, but you're not going to be able to write it using C#.
To create a native DLL, you'll have to write your code using one of the unmanaged C++ project types.
You can expose the DLL to COM. Have a look here for some examples.
yes you can.
you need to create second project.
the project must be unmanaged (like "visual c++"->class library).
the name of this procedure is "calling from unmanaged code to managed code".
good to read unmanaged to managed (codeproject)
you must be aware, that any computer that using your dll must have preinstalled DotNet and Visual C++ Redistributable Package
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