建立在Matlab共享库(.NET程序集),并在C#中使用它 [英] Creating a shared library (.NET Assembly) in Matlab and using it in C#

查看:402
本文介绍了建立在Matlab共享库(.NET程序集),并在C#中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab(2014a)使用应用程序编译器创建的.NET程序集,和我想要使用它在C#。

I've created a .NET assembly in Matlab (2014a) using the Application Compiler, and I'm trying to use it under C#.

在MATLAB模块只有1功能:

The matlab module has only 1 function:

function [ val ] = AnalyzePicture( arg1 )

val = 5;

end

导出.NET的DLL被命名为AnalyzePicture.dll,出口1级(如在Matlab应用程序编译器中定义)。 然而,当我尝试初始化它,我得到一个异常说:

The exported .NET DLL is named AnalyzePicture.dll and exports Class1 (as defined in the Matlab application compiler). However, when I try to initialize it, I get an exception saying:

The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception

通过内部异常俗话说:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

这里的code

Here's the code

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AnalyzePicture;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;

namespace Analyzer
{
    public class MatlabWrapper
    {
        AnalyzePicture.Class1 analyzer = null;

        public MatlabWrapper()
        {
            try
            {
               // The exception is raised here
                analyzer = new AnalyzePicture.Class1();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("f");
            }
        }

        ...

我的项目引用MWArray(8.3,现在的版本)和AnalyzePicture DLL(和DirectShowLib-2010)。

My project references MWArray (8.3, the current version) and the AnalyzePicture dll (and DirectShowLib-2010).

我试图在网上找到解决方案,但我无法找到如何正确使用Matlab的.NET程序集在C#中一个体面的例子。我没有完全按照<一个描述href="http://www.mathworks.com/help/dotnetbuilder/ug/integrate-your-net-component-in-a-c-application.html"相对=nofollow>之外,我的组装不启动这个文章融为一体。

I tried to find solutions online but i couldn't find a decent example on how to properly use a Matlab .NET Assembly in C#. I did exactly as described in this article besides that my assembly does not start with com.

这是什么可能会造成这个问题的任何想法? 任何code的例子将大大appriciated

Any ideas on what could be causing the problem? Any code examples will be greatly appriciated

(我使用Windows 7 64位,用Matlab 2014a 8.3 64位)

(I'm using Windows 7 64bit, with Matlab 2014a 8.3 64bit)

推荐答案

以防万一别人也会遇到同样的问题。 我前一段时间有这个问题,所以我想通了完整的解决方案这一点。

Just in case someone else will encounter the same issue. I had this problem some time ago, so I figured out complete solution to this.

您需要设置项目设置以使用.Net框架4.0(而不是4.5 VS 2013套作为默认版本),并改变目标平台,到x64。这套精美的作品在Win 8.1(x64)的,MATLAB R2013a(64,运行8.1版本)和Visual Studio 2013。

You need to set project settings to use .Net Framework 4.0 (instead of 4.5 VS 2013 sets as default version) and change target platform to x64. This set works beautifully on Win 8.1 (x64), MatLab R2013a (x64, runtime version 8.1) and Visual Studio 2013.

这篇关于建立在Matlab共享库(.NET程序集),并在C#中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆