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.
Related
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'm using the C++ wrapper in this link:
https://github.com/TekRTSA/RSA_API
In order to use a driver written in C++ inside C# project.
When I publish/release my C# project it doesn't work on other computers without Visual C++.
Is there any way that I can publish my project on computers that don't have the visual C++? Or is there any software package like .NET that I can use in order to make it work?
With .NET applications you need to make sure customers have a version of .NET that matches what you compiled your application with.
With (Microsoft) C++ applications that depend on the C Runtime, you need to make sure customers have a version of the Visual C++ Redistributables that matches what you compiled your application with. Do a google search for 'visual c++ redistributable' and you will see lots of suggestions on what to look for.
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.
Short Version:
Have: DLL's Managed Code (C#/Visual Basic) from Brüel & Kjær SDK
Need: Communicate with the DLL's in our old Project Un-Managed Code (C++ Visual Studio 2005)
Long Version:
We have a project written in C/C++ (Visual Studio 2005). Now I have to implement a communication with a new device. (Brüel & Kjær 2250SDK Noice).
The problem is, Brüel & Kjær only supports you with Libraries for C# or Visual Basic (Managed-Code) (Visual Studio 2010 and higher), but our project is an old unmanaged C/C++ code.
So, the question is, how can I work with the DLL's in my old C++ Code?
I don't have the source of the DLL's, I only have the DLLs.
I hope someone out there can help me with that problem. Thanks in advance!
What you want is probably C++/CLI (Common Language Infrastructure). It basically enables you to use .NET types in C++. With this you could call a C# DLL and use the data which is provided by the DLL as the .NET type. Since you already have you application in C++ code, I guess you don't want to rewrite it completely. You'd than have to convert the managed types to unmanaged types, which is possible with C++/CLI.
If you want to know more about it, here is a lengthy MSDN article about it and here is a useful little quick tutorial.
I have the source code of a C# program. I want to create a DLL out of it which I want to use in C++.
Is it possible to create a native DLL in Visual Studio 2008 which can be used in C++?
native <-> .Net interop is one of my pet disciplines, which is why I needed this as straightforward and reliable as possible.
The result was that I made me an MSBuild task which I just need to drag into a project to allow me to export static methods from pretty much any .Net language. And since the whole marshalling infrastructure works for exports as well, you can do pretty much anything with it that you want (like passing native/managed objects as IUnknown).
The resulting assembly will look to the consuming process like a real DLL, which means you can't have it to scale up to 64bit automatically anymore.
However, since you do have native bits in your application, you already have this issue anyways. ;-)
When you do not specifiy the CPU target in your C# project, my task will emit a warning that it created a folder for all targets (x86,x64 and Itanium), and there you'll have *.dll and *.pdb for each platform.
If you want the program to be native, and not managed, you'll need to port it to C++, instead of using C#.
That being said, you can compile it in C# into a library, and use it from C++ by using C++/CLI. This just requires that you compile the files that use the C# library with the /clr flag. This provides C++ access to the .NET framework, and lets you use libraries made in C# directly from C++.
Alternatively, you can use .NET's COM interop to expose the C# class(es) as COM objects, and then use those from native C++.
It is possible in Visual Studio 2008, but you're not going to be able to write it using C#.
To create a native DLL, you'll have to write your code using one of the unmanaged C++ project types.
You can expose the DLL to COM. Have a look here for some examples.
yes you can.
you need to create second project.
the project must be unmanaged (like "visual c++"->class library).
the name of this procedure is "calling from unmanaged code to managed code".
good to read unmanaged to managed (codeproject)
you must be aware, that any computer that using your dll must have preinstalled DotNet and Visual C++ Redistributable Package