Xamarin and c++ code - c#

Currently I`m exploring how to write mobile apps for Android using Xamarin and C#. Also I have some c++ libraries(and source code for them) that should be used in application. These libraries are responsible for communication via internet(just to say).
So it is possible to use this c++ code in xamarin.android project? Or it should be rewritten in c# to be used?

Im not sure with networking but most C++ code can be used 100% in Xamarin.
If it works, you can't be sure if it works correctly in every situation on IOS.
We had the same problem with using UDP Sockets for VOIP(C#).
Most of the time it will work, but in case of VOIP you need to use iOS sockets so you can set them to a special mode so they won't be closed when the app gets paused.
So it depends on what you want to do and how the C++ code is written.
Im not sure if you can use normal unix sockets when using C++ on iOS but that should be the only problem when using it.
Just checked: Does Mac/IOS use the same sys/socket.h as the Linux kernel?
I think, if your library uses BSD sockets everything should be fine.

Usually it is possible to call some code in any other library unless
It exports the functionality
There is a wrapper in your language to make use of that exported functionality.
I do not know much about this Xamarin thing but I guess you should see if the library is binary compatible not code (i.e) that compiles with the source of your C++ project and you can make calls to it from your C# program.
Also while checking the Zamarin library documents, it seems that not every piece of C# code can be used on Xamarin platform. Please check the Xamarin community and the forums for more in details.

Related

How does MonoRuntime lives side-by-side with ART?

I've read that applications which are being developed using Mono are deployed with a MonoRuntime that works similar as ART, interprets the C# code, executes them etc. I assume Unity and Xamarin both does this.
What is strange for me is that theoretically I could write a runtime and ship it with my app? But that is supposed to be next to the runtime, below the application framework? How can the sandboxing let this happen?
I assume this might be the solution to my confusion, but I struggle understanding it.
What am I missing here?
Thanks in advance
First think about how NDK/JNI apps work on Android. They are launched from standard Android Java code run via ART/Dalvik and use JNI calls into C/C++ code. The process is still within the standard Android 'sandbox' but has additional lower level access to libraries provided by Android NDK headers. As that code is written in C/C++ it can be performant/cross system compatible.
So to answer:
But that is supposed to be next to the runtime, below the application framework?
I would argue no, at least you aren't really below the Android application framework. The MonoRuntime is started from Android and can use any of the 'Standard Libraries' which are exposed either via a JNI wrapper to the Android Java side or by a NDK header.
If you look at the below diagram you'll see 'Standard Libraries' which can be OpenGL ES which has a Android Java API and OpenSL ES which exposes more detail in NDK than the Android Java media api.
I could write a runtime and ship it with my app?
Yes you could, although you may want to define clearly what you mean by 'runtime'. If you are pre-compiled you can strip out unnecessary classes/modules which I believe Mono does.
How can the sandboxing let this happen?
You are still in the sandbox. Nothing prevents you from writing your own interpreter / Virtual Machine written in C/C++, interfacing the Android framework through standard JNI/NDK calls, and adding it to your own APK. Regardless you are still limited to what the Android framework/runtime allows for apps along with same process restrictions and limitations.

Cross platform desktop development with HTML5 GUI

Short story: is there a way to write a desktop application with a GUI in HTML5 and core in a cross-platform language like python (or even C#/Mono)?
Longer story: I'm a C# developer, for small personal projects I seldom do, running both under Windows and OSX, I use C# (Mono) with a frontend leveraging on Eto.Forms
I'd like to understand if there's a mature way to achieve the same results using an HTML5 GUI, since I'd like to learn that and believe it could be a good option for near-future Windows desktop UIs (or otherwise a nice tool to have in my skillset). Of course if the code running behind the scenes is C# I'll be more than happy, but also getting my feet wet in another, maybe more cross-platform like python would be good.
At this stage I'm not interested in any mobile-oriented solution.
Electron (formerly Atom shell) has really matured as of late. In fact it's what VSCode is built on.
There's a great tutorial and starter code on using Angular 2 and Typescript, and you can even use VSCode to write and build it.
For me this is the best way to transition from the WPF world to HTML5.
the NW.js look pretty promising... you might even be able to use TypeScript which would be much closer to C# than plain ol' js. If you're open to using PHP, you can check out the nightrain project https://github.com/naetech/nightrain.
Give http://www.tidesdk.org/ a try.
Your app will run on Windows 8, MacOS and Linux. You can use HTML5, Javascript and CSS3.
But you can also extend the functionality of your app with a scripting language you are comfortable with. TideSDK currently supports Python, PHP, and Ruby.
I have recently worked with Chromium Embedded Framework, basically a browser component for WPF an WinForms. It works very well and provides kind of a two-way interoperability from website to .NET-app and vice versa. Basically, you:
Create a WPF desktop app
Include CEFSharp and place a full-screen browser on the window
Call methods in JavaScript:
// .NET
var mainFrame = browser.GetMainFrame();
mainFrame.ExecuteJavaScriptAsync("any js code");
Bind a .NET-object
// .NET
browser.RegisterJsObject("boundObject", this);
Call methods on a bound .NET-object from the website/JS:
// JS
boundObject.someMethod();
On this basis you could build a mediation layer (ViewModels, controllers, ...) between HTML/JS-UI and .NET logic...
I wrote an APP with http://kivy.org/ it is capable to create apps for different systems.
Qt node https://github.com/arturadib/node-qt seems also interesting, but i did not test it myself.
And last https://chrome.google.com/webstore/launcher
You can create web apps for chrome, which should run in supported systems.
Kivy is a Python solution. Qt node is maybe what you are looking for.
Here are some nice tutorials for kivy:
https://www.youtube.com/playlist?list=PLQVvvaa0QuDe_l6XiJ40yGTEqIKugAdTy
NW.js
But it's Javascript (node), not python nor C#.
A very interesting project I think is Chromium Embedded Framework. You basically embed a (stripped down) web browser in your application. For python, many GUI Toolkits are supported. Check this for more information.
Since you are used to C#, maybe Java with JavaFX and FXML is an option. FXML is not HTML but you can style it with CSS as well. You can also use Scene Builder with it for faster UI creation. Many JVM languages support this toolkit so Jython instead of Java will also work. I will recommend Java however, because the support for other languages, while there, is not perfect yet.
Using C# and the Windows App Store WebView is also an option. You can check MSDN for more information.
I am sure there are other options (Kivy, Node.js, etc.) as well. Some of them are already mentioned in this thread.
I would recommend Node-Webkit which is based on nodejs.You can still use some python scripts to do some backend job integrated with Node-Webkit which is easy to deal with.I've already saw some successful applications using this(like wunderlist).TideSDK is another choice but the python support in TideSDK is not mature enough.The Node-Webkit project hosted at
https://github.com/nwjs/nw.js/

FastCV and Windows Phone 8 (C#)

I want to build a Windows Phone 8 (C#) application with Qualcommm's FastCV. It's very simple with Android, about I have problems with Windows Phone because there isn't any documentation about it.
After installation FastCV SDK v1.5 for Windows Phone, I have a header file (fastcv.h) and a .lib file (libfastcvnative.wp63.lib). How can I use/refer the both C++ files in VS 2012/2013? Are there also a tool like CDT in Eclipse?
At Qualcomm's Dev-Forum there is a solution, but I cannot understand it.
Another question: Are there others computer vision (object detection, text recognition ..) for windows phone 8 - maybe with a better documentation?
Thanks!
I came across over this CodePlex project. It seems to be doing what you need. If it does not work, you could try the approach below.
One problem is that C# is managed code, while FastCV library is probably native code.
So you would need a wrapper that "forwards" the FastCV functions you intend to use. Native Code and Manged C++ interoperability is more easy to have as you can have managed code and native code even in the same file. See here for more details.
So you need to make a manged C++ library, load it as an assembly from your C# project and consume it from there. The C++ managed library will just call the native FastCV functions.
Are there others computer vision (object detection, text recognition
..) for windows phone 8 - maybe with a better documentation?
Yes. You can have OpenCV for Windows 8 / 8.1. Check here for more information. It's not guaranteed to be optimized better than FastCV but I have a feeling that it's much more complete than FastCV functions. I would go with OpenCV before FastCV.

How does Xamarin for Android (Mono for Android) compare to native Android development?

I've recently chosen to learn C# and develop mobile apps using C# on Xamarin. Particularly for Windows Phone and Android development. I know that Windows Phone app development is mostly C#, and that Xamarin can compile native code for Android, but how does it compare to native development in Java? Will I be able to use EVERY or at least most (like 90%+) of the Android SDK and extensions using Xamarin?
The main thing which I think there is to consider is your preferred programming language - which in your case is C# - and using that. The only thing that is of concern to me when building an app in C# as oppose to Java is their is not as many 3rd party references to use as there is with Java. You will find yourself downloading example files and reverse engineering them in order to learn how to do new features, you will have to search intellisence far more to find what something is using if you can only find a Java based example of something. One thing which you will find though is that it usually can just be the same method as what is in Java but the first letter being capitalized. LINQ is a major benefit I find in data manipulation which is not available in Java.
Good luck with whatever you choose, James
I did not do any stats or study of Xamarin C# coverage of Android Java API, but in my work, everything that I needed when porting code from Java to C# was there. Also, Xamarin says that for new Android SDK releases they usually have C# counterparts released within 24 hours. And, as #dotToString remarked, you can add Java jar libraries to Xamarin C# project and make calls to them if necessary.
Performance is another matter - I don't believe it runs natively on Android. Rather, Mono runtime is somehow interpreting the byte code. I did some comparison of Java vs. Xamarin C# code performance on real life code, see more at:
Does anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java?
Greg
you can use all of the android functionality and java library interop. also, you get the advantage of non windows specific .net including linq.

WPF with C++, is it possible?

I have my main program in C++, but now I need to build a beautiful application and I know that WPF is easy and makes for beautiful apps. Can WPF work with C++ or C# and C++? (If yes, how?) Is WPF the best thing for me?
You can use WPF in a managed C++ project, but you're better off keeping your C++ in a separate assembly and referencing it from a C# or VB WPF project.
Yes, you can develop a GUI using WPF framework in Managed C+ or C++/CLI. But they're not Standard C++, hence not cross-platform.
If you just want a GUI for your application written in C++, then you may try Qt as well. The advantage in Qt is that its completely in C++. Not Microsoft Managed C++. The second advantage is that its cross-platform toolkit. That means, you can run your app in Windows, Linux, Mac, and on other machines as well.
Have a look at its documentation
Qt Reference Documentation
It has lots of tools for fast development such as Qt Creator, Qt Designer and others. You can see all of them by browsing the above link.
WPF is dead along with Silverlight, remember, MS says its HTML5 only from now on :)
Using WPF in your C++ app can be achieved using hwndSource, but its not the optimal solution, for that you will have to create C# or VB.NET GUI app, and use it to communicate with your C++ app via some form of IPC.
There are alternatives, probably the best one is to write your GUI using Qt, which is very well respected. You can get similar features to WPF by writing using QML alongside the old forms-based system (which means you get all the development speed of using the old, boring text boxes and the like, and the fancy GUI benefits of using the new declarative UI system, all in the same system. sweet).
Of course, a decent option is to make your app into a back-end server process and call it from a web-server based HTML5 UI. That's pretty future proof, easy to deploy to clients, and as modern as you're likely to get.

Categories