I would like to share common code between a Xamarin.Forms project (C#) and a Qt project (C++).
Have you got a solution?
I try with a Visual C# Class Library which builds a DLL file. I succeeded to reference and use it in the Xamarin.Forms project, but I failed to use it in Qt. I supposed this is because the DLL is compiled from C# code.
Thanks.
If you can put the shared code in your C# dll, you should be able to use it from Xamarin (depending on what libraries it uses) and also call it from your C++ code.
Related
I'm going to add a DLL which is made inside C# .net to a C++ project.
According to instructions inside some references like this, I should add its reference as below:
Properties --> Common Properties --> Framework and References -->Add new Reference
In windows which titled Add Reference I should add DLL to my C++ project.
However this windows does not show any DLL files and have no options to browse DLL files.
Does anyone know how can I bring my custom DLL into this window?
P.S. Whole this story is about the requirement that I want to connect SQL Server inside a C++ project and I don't want to use C++ libraries. Instead I want to implement SQL related stuff inside a C# class library project and import it inside C++ project using C# project DLL. If you have any ideas about this I would be grateful if you share your idea or solution.
You cannot call managed (i.e. c# methods) from a native (i.e. c++) project without jumping thru some hoops. You have a few options:
Make your project a c++/cli project, this will allow calling managed code directly. This would probably be the easiest, it should not be much more complex than turning on support for "common language runtime support" in the advanced project properties.
Use a c++/cli adapter project between your native and managed code.
Use some thirdparty software to generate native exported functions by some black magic.
Rewrite your application in c#
For a c++/cli and c# projects you should have a "References" entry in your project that you can use to add assemblies to. I'm not sure if nuget works however, so you might need to managed the references manually.
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.
We have a requirement to import a C++ legacy dll inside C# UWP application and access the methods inside the c++ classes. We don't have the source code with us, So not able to do with the Windows Run time component.
Please let me know how can I import the c++ dll inside the Visual C# universal windows application.
I am able to add the dll as a reference in visual C++ application, But not able to do it in visual C# uwp application. I have tried the dllimport but it is throwing dll not found exception.
Firstly, UWP can't import a legacy C++ dll just by DLLImport.
If you want to import legacy c++ functions to C#, the first suggestion is to wrap that C++ logic using a WinRT component.
And if you want to PInvoke the dll, you can follow these steps (You can refer to this thread): First, add dll into your UWP project making sure to set its type as 'content'. Then in the proper cs file, using DllImport to PInvoke the dll.
In addition, you need to make sure your dll is not using prohibited APIs in WinRT. You can check this by using /ZW compile option for the dll. There is a similar thread, you can refer to it.
I have created a C++ static library for ios (XCode 6.1) in visual studio. But when I compile this project, the output .a file is getting created in Mac machine and not getting copied back to Windows. My concern is that how can I refer this static library in an iOS C# application project in Visual studio?
So you have several options here, what you need to do is to have a Dll that contains the native .a library and the resources/code to interop with the native c++ library (and reference that Dll in your Visual Studio Xamarin.iOS project). You can use a Xamarin iOS Binding project as a container and one of the following options
You can use swig to wrap the c++ lib and there is actually a video from Xamarin University lighting lectures from Chris Van Wyk that describes the process.
You can use Mono CppSharp to wrap the library (My personal favourite easier to use than swig).
You can write your own c wrapper around the c++ library and P/Invoke that from C#
You can write your own Objective-C wrapper around the c++ library and use a Xamarin.iOS Binding project to interop with it.
Hope this helps.
I would like to use an android project in xamarin for example this one: https://github.com/jaydeepw/poly-picker
This project is written in java and has resources and activities.
As far as I understand it is not possible to compile such a project into a jar and then to create a binding library.
Is this correct?
What options do exist to use such a project, apart from porting the source code?
Unfortunately, only you can binding Java libraries, not apps.
You can read this post:
https://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding_a_java_library_(.jar)/