Android projects run natively on Java, and NDK projects basically work by having a special Activity that launches your native code. For example, SDL has an Activity that initializes SDL, sets up a display window, and then launches your project.
I'm trying to see how Xamarin does it. Technically, CLR code is managed code rather than native, but the CLR itself is native code and the whole thing would look like an NDK project to the Android runtime. I've been looking around, but I can't find where the Android project launcher is in Xamarin, and Googling it turns up nothing useful.
What is the mechanism by which Xamarin launches your CLR project on an Android device?
What is the mechanism by which Xamarin launches your CLR project on an Android device?
You can refer to Application Startup.
When an app is launched in Android device, Android will load it by specified #android:name in manifest, then usually all types will be instantiated by invoking ContentProvider.attachinfo() method, Xamarin.Android then here adding a mono.MonoRuntimeProvider ContentProvider during the build process. The mono.MonoRuntimeProvider.attachInfo() method will then replace the native ContentProvider.attachinfo() method to load Mono runtime into the process.
This is how I understand that document, please advise me if there is any mistake, many thanks.
Related
I have created a UWP app for Windows 10 using Visual Studio 2019 that I want to utilize a library of functions when a button is clicked.
Here is the template I selected when creating my UWP app.
I chose to write the library using a Windows runtime component written in c# thinking it would be easily imported into my UWP app to where I could call the functions when a button is clicked on the UI. The Windows Runtime component will eventually need to be portable to other software which is why I am creating these two separately. The library has to have the ability to read/write to a USB port which is why I didn't chose Class library template. The class library doesn't allow you to import "System.IO.Ports", but the Windows runtime component does. I have very basic code in my library at the moment so if the Windows runtime component is not what I should be using please offer other suggestions.
I have seen tutorials calling functions from a component in JavaScript, but couldn't find any showing how to call functions from my Windows Runtime Component in a UWP App written in C#.
Project Directory showing where I would like to call these functions.
UI created with XAML
VS2010: Use namespace from another project within the solution?
^^ Figured out I just needed to add reference of Windows Runtime Component to my UWP App.
In my VS2017 solution, I created a UWP and .NET Standard Library 2.0.3 projects. Referenced Library project from UWP. Library project is using a System.Diagnostics.Process to start a process. In debug mode, I get access denied error at line Process.Start(...) of the code inside Library project.
I thought the purpose of new .NET Standard Library project was to support various platforms (.NET, .NET Core, UWP etc) uniformly. But I guess, the sandbox nature of UWP apps is probably not allowing me to run Process.Start(...) albeit the process is running inside Library project. Question: What I may be missing and/or how can we resolve the above issue?
You cannot launch process directly from UWP, but there are some alternative ways to do that. The first one is using FullTrustProcessLauncher, if you need some example, check this post series. Another way is using a WPF or WinForms application to host UWP Controls with the Xaml Islands where there aren't restrictions to call any .NET APIs, but remember, through this way, your app will work only on Desktop devices.
According to this answer, you can't use Process.Start in a UWP app. There are some alternatives for launching other apps, but you can't execute arbitrary .exe or other processes.
i want to import some C++ unmanaged dlls into my windows phone app. can i do this ?? while debugging the dll not found exception thrown. can anyone help me to where do i place my those dependency dlls .
thank you ...
It depends on the DLL. If the DLL is built using only API available to Windows Runtime apps then you can use it. See Win32 and COM for Windows Runtime apps on MSDN for a list of the available API. You won't be able to use a DLL built for a desktop system (you cannot run x86 or x64 on ARM) but will need a specific phone build.
To use it you will need to include it in your appx package. In Visual Studio's Solution Explorer add the DLL to your project and edit its properties to mark its Build Action as Content. When you build the app check to make sure it is in the appx directory. That will deploy the DLL with the app so it is available at runtime.
For me it was due to having WIC code in my App and/or calling CoCreateInstance in a windows phone environment ( on PC it works flawlessly though )
I have a C++ (Native code) DLL project developed for iOS and Android. I would like to port it to a C++ DLL (Universal Apps) to be consumed by a C# Universal Store Application. The code isn't HW dependent.
As a first step, before moving all the code, I created a small test solution as follows:
I created a C++ DLL (Universal Apps), myDll, that has a C++ Add1(int, int) function.
I created a C++ WinRT component (Universal Apps) that has C++ Add2(int, int) function.
I created a C# Universal Application, myApp, that calls Add2 which calls Add1.
Compilation passes OK, however when I run myApp the application crashes and report that myDll wasn't
loaded.
My questions are:
Is the scenario I described above possible? And If so, what can be the problem causing myApp to crash?
Is there a better way for me to port the iOS/Android C++ code to be consumed in a C# Universal Application?
Thx
1) Like Hans, my first guess is that you're not including the Dll in the apps package. If it's not deployed in the package it isn't available to be loaded. Since you can't add a reference to the DLL you'll need to add it explicitly:
Add the files to the project, open the files' properties in the Solution Explorer window, and mark them as content to be included in the app package.
Check that out is actually in the appx dir after you deploy.
2) That's probably the easiest. You could also include just the Dll and pinvoke. Either way you'll need to make sure the dll is valid for Windows Store apps
I have made a Kinect Application in Microsoft Visual Studio 2010. I need to make an exe of the application which can run on any windows based system. If I need to do that than is there any requirements that the system should fulfil? and If yes, then how do I do that?
I tried to use the exe in application/bin/debug/application.exe by copying it in another folder but it shows an error but if I run the exe from the bin/debug/application.exe it works. Am I missing something here or is it the only way to do that?
"Any Windows based system" isn't going to work. Assuming you're using the Kinect SDK, it will only run on Windows 7 (and supposedly Windows Server 2008). The computer running the application will need either the Kinect Runtime, which only works with the new Kinect for Windows sensor, or the Kinect SDK, which also works with the Kinect for Xbox. Microsoft wants to sell more Kinect for Windows sensors, so they don't allow the runtime to work with the old Xbox Kinects. Makes sense in a way, but man that bugged me when I first found out about it. There's a short post showing how to test for the existence of the Runtime on application load, so you can show an appropriate error message instead of just crashing out.
You need to copy any files that the program relies on, such as DLL files, along with the executable. There's instructions here for how to embed the DLL files into the executable; I've not tried it but it might be worth a shot.
The correct .NET version should be installed when either the Runtime or the SDK is installed; you shouldn't have to worry about this.
#Coeeffect is right, but you can also publish version 1.0.0.0 of your app by going to project -> properties -> publish -> publishing wizard to publish your application to then use on ther computes ect. Hope this helps!
You need to copy all non-standard DLLs that your program uses.
The target computer needs the appropriate version of .Net.