I have core functionality written in c++.
To use this from UWP, I made dynamic library and chained like this: [c++ native dll] - [c++/cx windows runtime component] - [UWP c# class library].
c# dll provides API for UWP and c++/cx is used just for interoperability between c++ and c#.
My test UWP app works fine and now I want to distribute my dlls.
Is there a way to distribute my dlls in all-in-one structure? (like aar)
If possible, I want to make one library for UWP encompassing above [c++ native dll] - [c++/cx windows runtime component] - [UWP c# class library].
Any hint or resource would be grateful
Thank you in advance.
Is there a way to distribute my dlls in all-in-one structure? (like aar)
You may refer .NetStandard library, and mix them in one .NET Standard library. And if you want this library could run in the multiple platform, you need to refer Xamarin Forms class library structure, for more detail please refer this blog.
Related
I'm working on the port of the C# UWP project to Uno-Platform. The original project references a lot of logic from C++ DLLs. The interface between C# and C++ library is rather big to write PInvoke wrappers manually.
Is there any complete solution to automate the calling of C++ library methods from .NET?
The Uno Platform does not provide anything specific for this type of scenarios, and relies on what .NET already provides (P/Invoke in this case).
You may want to take a look at https://github.com/EgorBo/CppPinvokeGenerator or https://github.com/xoofx/CppAst.NET to generate C# from the C++ code.
I have Universal Windows C# class library with UI components. I was wondering if I can use it from Native C++.
I tried to use regasm to convert class library dll into tlb file, but it throws error
Error: Assembly must not be a Windows Runtime assembly.
Also I tried to make a WinRT/WRL wrapper for C# class library, and tried to load it from Native C++. But when I call LoadLibrary for wrapper dll, it returns 'nullptr' with 126 error, even though all dlls and executables are in the same directory.
So how can I use Universal Windows class library from Native C++? Is it possible?
You will have to expose your class library as COM component and call it from native code, this is the most convenient solution.
you won't be able to call Universal Windows C# class library from native C++, as it won't be recognized and, as you mentioned in your question, it will cause a nullptr exception.
The interesting things is, you can do the other way around!
you can create a native C++ library and call it in Universal Windows C# platform - there is whole post in MSDN regarding this practice:
Use Existing C++ Code in a Universal Windows Platform App
funny thing in my opinion you can do one thing but not the other way around but still, it's good to know that at least one way is actually possible.
I am not sure "convenient" is the word I would use to describe exposing native C++ as a COM component.
You should take a look at C++/WinRT
https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis.
It appears to supersede C++/CX which was Microsoft's initial approach to allow C++ to be used to build and use WinRT components.
We have one application for both C# .NET and Apple iPad. This application will perform similar functionalities. For this we have one protocol layer which we are thinking to keep as common code. For this we are thinking of creating a C++ dll for the protocol module so that it can be used across both C# and iPad. For creating a C++ dll, I have a basic question:
While creating a dll project, which option should we select? We can create a dll for MFC, Win32, ATL etc. What would be the best option for my requirement?
You should not use MFC as these are the Microsoft Foundation Classes not available on iOS anyway. Probably Win32 would be your best guess - but make sure not to include any non-standard Windows header files if you want to use the DLL in non-Windows environments.
I would recommend to frequently compile your file in both environments. You might also want to take a look at multi-platform libraries like boost if you need advanced functionality.
I recommend looking at Mono for building C# apps on both Windows and iOS.
If you want to target the iPad, you need to build for iOS, not Mac OS.
You cannot build dynamic link libraries for iOS, only static libraries. Note, there are equivalents to DLLs on iOS, but only Apple can build them (or you can build them yourself if your iPad is jailbroken, but this will disqualify your app from the AppStore).
iOS is not related to Windows in any way, so Win32 libraries will not run on iOS. Your generic 'protocol module' (if you mean low-level code that can interface to other devices over TCP/IP or similar) will need to have significant differences depending on which platform it is running upon.
So, I want to share TONS of code between Silverlight and "normal" applications. Starting with utility functions and all that up to my hand coded framework (MVC, DI, etc...)...
Here is my question:
Imagine I have put all this stuff into a SL - Classlibrary, lets call it "AmazingLibrary" and I reference it in a NORMAL (say, WPF) project that doesn't use Silverlight...
Will I have to make the people enjoying my WPF - application install Silverlight first or is the assembly just "a little bit different, but still runs under normal CLR 3.5"?
No, you shouldn't need to have people install SilverLight to use your external library. The SilverLight class library can just reference a subset of what is in .net.
Here is a link describing the differences between a normal library and a SilverLight library:
http://www.scribd.com/doc/17088869/SilverLight-Class-Library-vs-Normal-Class-Library
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.