Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab "stand alone" DLL and C#

Subject: Matlab "stand alone" DLL and C#

From: Damjan Vengust

Date: 14 Feb, 2007 14:19:36

Message: 1 of 5

Hello!

Here is what I want to do.
I would like to create a simple function and then build a stand alone
library.

Then I would like to call this function from C# (.net 2.0).

DLL must be stand-alone, so I don't need to do any installation on
client computer. (if any installation is required, it should be
silent --> without any user interaction)

Best regards,
Damjan

Subject: Matlab "stand alone" DLL and C#

From: Titus

Date: 16 Feb, 2007 10:59:43

Message: 2 of 5

Hi,
you can use the MATLAB Compiler (or MATLAB builder for .NET)
http://www.mathworks.com/products/compiler
http://www.mathworks.com/products/netbuilder/

but you will always need to install the MCR (think of it as the run-time
environment for MATLAB) on the client machine (this needs to be
done only once, see the chapter of "Deploying Applications" in the
online help following the links above).

Titus

"Damjan Vengust" <pivo_pijem@hotmail.com> schrieb im Newsbeitrag
news:ef4dd59.-1@webcrossing.raydaftYaTP...
> Hello!
>
> Here is what I want to do.
> I would like to create a simple function and then build a stand alone
> library.
>
> Then I would like to call this function from C# (.net 2.0).
>
> DLL must be stand-alone, so I don't need to do any installation on
> client computer. (if any installation is required, it should be
> silent --> without any user interaction)
>
> Best regards,
> Damjan

Subject: Matlab

From: John Reilly

Date: 15 Feb, 2007 10:25:19

Message: 3 of 5

Hi Damjan,

You can call *any* exported Win32 DLL entry point from C# using
P/Invoke (Platform Invoke), so that isn't a problem.

I'm guessing that you want to create your simple function using the
MATLAB m script? If so, you'll need the MATLAB Compiler to compile
that into a DLL. To run, you'll be required to install the MATLAB
Compiler Runtime (MCR) on the target. I believe it can execute
silently.

Good luck.

john.

 Damjan Vengust wrote:
>
>
> Hello!
>
> Here is what I want to do.
> I would like to create a simple function and then build a stand
> alone
> library.
>
> Then I would like to call this function from C# (.net 2.0).
>
> DLL must be stand-alone, so I don't need to do any installation on
> client computer. (if any installation is required, it should be
> silent --> without any user interaction)
>
> Best regards,
> Damjan

Subject: Matlab

From: Damjan Vengust

Date: 15 Feb, 2007 16:48:58

Message: 4 of 5

Hey John,

Thanks for your answer.

I found a recorded webinar that explains deploying Matlab
applications.

.Net builder was mentioned in the tutorial. Of course I have to check
it out. After a while I was able to make .net assembly and include it
(as a reference) into my C# project (VS2005).

Here are my sample files:

% mySum.m
function [result] = mySum(a, b)
    result = a + b;
end

// C# - Windows Application
private void button1_Click(object sender, EventArgs e)
{
    try
    {
       // TypeInitializationException: The type initializer throw
exception
        Operationsclass o = new Operationsclass(); // <--
Exception thrown here
        o.mySum(1, 2);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

After some blind clicking, I found checkbox to include MCR (Matlab
Runtime Component). Then I built a package (150MB).
After installing a package my C# App seems to work fine.
(Haven't checked yet on target computer -> without matlab
installed).

Is this the solution?
1. Make .NET Assembly
2. Include MCR into package
3. Silently install MCR
4. Install C# Application
5. Run Application

Regards,
Damjan

Subject: Matlab

From: Damjan Vengust

Date: 18 Feb, 2007 08:55:15

Message: 5 of 5

Hello!

All problems solved!
Thanks a lot guys.

There is only one thing left.
I need to find a way to include MCRinstaller into VS2005 Setup
project or some switches to silently install MCR.

Regards,
Damjan

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us