Using MATLAB functions in C# - c#

I want to use a function in C# (2010) generated by a MATLAB Builder for .NET component (R2009a). The system doesn't have MATLAB on it. So, I want to know how can I do this work?
I have installed MCR 7.1 on this machine, But when I want to add .Net MWArray API in my references I can't find it in the .Net DLL list in C#.

I don't think you can extend the C# program you originally produced with MATLAB Builder. The output of MATLAB Compiler is a complete program or library intended to be run on its own, and the EXE is digitally signed to prevent modification. The MCR only allows signed programs to run; it does not include anything but the bare minimum of libraries.

Related

Surfacing a large C++ library in .net-core

I have a large C++ library (1000's of objects) that I'd like to be able to access in C# on Linux.
Some background:
The code has 1000's of objects
The objects are often passed in as parameters, sometimes by reference and sometimes by a pointer
The code is compiled native on Linux. It is open source so I can adjust how it is built if I like, though I can't alter the C++ code.
I need to replicate the object code in C#
I've done this once on windows: I can parse and write out .cpp files that are wrappers and use the c++/cli for doing the interop. This works.
There is no reason I can't do the same process to build .netcore interop files on the Linux side. I just have no idea how to go about doing it. I've read that PInvoke is supported. Is that my only option? Turn every method call, etc., into a C-like method call?
At the moment I do not need to do the same on Windows - just on the Linux side. So any solution that is Linux only is acceptable. I've already got a Windows-only solution using .net standard.

using c++ wrapper in c# .NET project

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.

How to reference ubuntu MATLAB runtime libraries in C#?

I have a C# program that uses the MWARRAY.dll from MATLAB. I am trying to run this program on Ubuntu with mono. But, it keeps saying the MWArray.dll was not found. I have install Matlab runtime on my Ubuntu machine. I wanted to know how to reference Matlab ubuntu libraries in C# code. Is it even possible?
You can use DLLmaps to map library names for specific operating systems. For example, you can put a line like <dllmap dll="some.dll" target="libsome.so" os="!windows"/> in your /etc/mono/config file and it will be mapped for every project.

Statically link COM DLL in C# (avoid regfree)

I have perhaps a silly question:
We have a VC++ COM DLL (developed internally) and we have ported our main app to C# and used COM Interop, reg-free to access the COM dll. Everything works just fine with internal embedded manifest.
However, the friendly product-dev/marketing/sales want to minimize the package and include the COM dll directly. Somehow, someone became convinced that the app distro should include the exe only (since it's unmanaged we can't just ILMerge it in).
Since we have the tlb/lib of the COM, could we somehow statically link it, without porting the whole COM to C# managed re-work?
Thank you
P.S. Pardon my wording: the company was downsized and I am the Python guy who had to learn everything .NET in the last week or so since now I am doing my job and the job of 2 ex-senior .net developers
It looks like Costura can more or less do this.
https://github.com/Fody/Costura
It specifically has support for merging unmanaged assemblies (ie a C++ DLL) into a .NET assembly.
Note - this is not true static linking but would achieve the aim of packaging everything in the single EXE to be distributed.
It is possible to include the source for the COM DLL into the project for the exe, or you could change the COM DLL project into a static lib project. Once you've accomplished that, you must modify the code to create the COM objects directly. All said, neither options are particularly easy.
Alternatively you could look into products like Spoon Studio that would allow you to wrap your exe and COM DLL into one exe without any code.

How to create native DLL in Visual Studio from C# code?

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

Categories