For Cordova iOS and Cordova Android it is possible to create plugins that create native UI on top of your app - you just include the libraries in your plugin and execute their API. Example for Android InAppBrowser.
For Cordova Windows, the native code is HTML and Javascript, hence the InAppBrowser plugin also adds a standard HTML tag for a Webview (or even plain Iframe) to get the same effect.
But you can also create plugins for Cordova Windows that use C# or C++ native code via a Windows Runtime Component. A public example is the globalization plugin that uses a .winmd file to offer APIs to the Javascript code (source code for this). This works great and is pretty awesome.
Unfortunately all the plugins that I could find use this C#/C++ native plugin mechanism only to receive some method call, do something with the parameters and return some data. None of those open any windows or create any other GUI (that might for example be offered by an external C# SDK).
How can one create a plugin for Cordova Windows that creates User Interface with native (C#, C++) code? Is this possible at all?
Got a response in a Apache Cordova mailing list that I am reproducing here:
Unfortunately, No. C#/C++ Portable Class Library ( PCL ) code cannot
render on top of the web component.
The libraries that you can use are limited in PCLs and for projects
targeting Windows Store it is not possible to render UI.
If the entire cordova-windows platform were re-architected to be a C# or
C++ based application, with a native webview container in which to render,
then everything is possible. This is a long risky road though ...
everything from the cordova.js and the bridge would have to change, and
every plugin would need to be rewritten.
Related
I just got back from Microsoft Build 2018 where they announced .NET Core 3 support for WPF applications. This is great because I can finally start using some of those cool fluent design things that are available for UWP. The only problem is, it's not getting released until next year.
I started looking into converting my app to a UWP app (because I'm impatient) but I'm running into some challenges. Mainly hardware. Talking with a few guys at Build, they made it seem like it was possible to write UWP apps that connect to low-level Win32 drivers for communicating with hardware (HID printers, card readers, bar code scanners, etc). I'm not having any luck finding information about this. Just to be clear, this is not an app I want to release to the Windows Store. This is a kiosk app that runs on our own hardware.
How does one access Win32 APIs for hardware integration in UWP?
Your best bet is likely to use P/Invoke, which is technology designed to allow .NET code to call unmanaged code. Assuming that your hardware is accessed through Win32 APIs in a DLL, this may be your best option.
The pinvoke.net Web site provides specific examples of the .NET code needed to call a specific Win32 API. Perhaps those examples can help you get started.
UWP app written in C++/CX has access to the Win32 and COM APIs that are part of the Universal Windows Platform (UWP).
The APIs in Win32 and COM APIs for UWP apps is only for C++, you can not use the C# to access it directly. Please see Visual C++ Language Reference (C++/CX) to get more details about C++/CX.
But, you can create a Windows Runtime component in C++/CX, then call it from C#, you can see the Walkthrough here:
https://learn.microsoft.com/en-us/windows/uwp/winrt-components/walkthrough-creating-a-basic-windows-runtime-component-in-cpp-and-calling-it-from-javascript-or-csharp
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.
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/
I've made an .Net Dynamic Link Library, written in c#, to be used in Silverlight applications.
Now, I want to have the same kind of functionallity to be used when developing Adobe Flash applications. I'm not that familiar with Flash or ActionScript. I don't even even know if there are some kind of DLL equivalent in Flash/ActionScript.
Any suggestions? Do I have to go the long way, i.e. learn flash and develop this functionallity or, is there a smoother way? A .Net to ActionScript converter?
No.
But you could consider exposing such assembly (DLL) functionalities through a Web Service API, and let both Silverlight and Flash apps access them remotely so both can share the same implementation of your backend.
That will work if the whole assembly it's not doing real-time processing or something like that and the whole Silverlight and Flash apps are browser-based ones. In that case, you can develop an ASP.NET Web API (REST) and do the work in the service.
Later you'll be asynchronously querying the Web API from Flash and Silverlight.
Long time listener, first time caller. Does anyone know of a good interop library for the Win32API?
I found pinvok.net which is OK.
(FWIW I got the addin to work with MSVS 2010 by following the instructions here:
http://www.red-gate.com/supportcenter/GeneralContent.aspx?c=knowledgebase\PInvoke\KB200711000198.htm
and using 10.0 instead of 9.0)
...and the Windows API Code Pack 1.1 from MSDN seems not to have the basic Win32 stuff from user32.dll or am I missing something?
More specifics...
I am trying to take an external window and make it a child of a control in my managed System.Windows.Form (embedded GUI in a panel or tab of my main form). Researching here and on google it seems like Win32/user32.dll is the way to go. My application is a framework that launches 3rd party GUIs (dlls and exes). The 3rd party code/forms are all unmanaged (mostly MSVC) code. These unmanaged forms are launched from within my process hierarchy. My preference would be to stay in .NET if is possible.
The best interop library available is the .NET Framework. User32.dll is wrapped very well by Windows Forms.
The Windows API code pack concentrates on wrapping API additions made in Vista and Win7. Those were not additions to user32, mostly shell stuff.
You'll probably get a better answer if you can be specific about exactly what user32 APIs you want to use.
After seeing edit: what you are trying to do is explicitly forbidden by the Win32 SDK documentation. The parent of a window must belong to the same process. There are however some appcompat hacks in Windows, designed to support Windows 3.x programs where this restriction did not exist. Because it didn't support threading.
You can try, but beware you'll void the warranty. P/Invoke SetParent(). Visit pinvoke.net for the declaration you'll need.
Much of the Windows 32 API is exposed in .NET in the framework itself - so it's rare that you need to P/Invoke into user32.dll. You're better off using the managed versions of the framework.
When you do need to setup a P/Invoke call, pinvoke.net is a great resource for the specific API required for a call into most of the Win32 API.