2

I ran into problems in MATLAB R2010b when creating a DLL that uses .NET-integration and enumerations with encapsulate data.

Example:

  1. There is a .NET Assembly which is used in MATLAB, let's call it "MyAssembly" (MyAssembly.dll).
  2. There Matlab Enumerations Class "OpenMode"

    
    classdef OpenMode
        methods
            function obj = OpenMode(netType)
                obj.Net = netType;
            end
        end
        properties
            Net
        end
        enumeration
            ReadOnly  (MyAssembly.OpenMode.ReadOnly)
            ReadWrite (MyAssembly.OpenMode.ReadWrite)
        end
    end
    
    This class uses the .NET enumeration: "MyAssembly.OpenMode" In such a way to access the .NET-enumeration via Matlab-enumeration (In my case it is necessary for cast types):
    
    netElem = OpenMode.ReadOnly.Net;
    cls = class(netElem)
    cls = 
        MyAssembly.OpenMode
    
  3. The Matlab-Function, that should be exported:

    
    function retVal = MyFunction(inputs)
        NET.addAssembly('MyAssembly.dll');
        flag = OpenMode.ReadOnly;
        netFlag = flag.Net;
        % Some code...
    end
    
  4. Add .NET Assembly in Matlab (checking)
    
    NET.addAssembly('MyAssembly.dll')
    
  5. Try to compile the Dll:
    
    mcc -B csharedlib:MyLib MyFunction
    
    ...and get the error:
    
    Depfun error: 'Undefined variable "MyAssembly" or class "MyAssembly.OpenMode.ReadOnly".' 
    ??? Error using ==> mcc
    Error executing mcc, return status = 1 (0x1).
    

The mcc compiler does not detect in code enumeration that "MyAssembly" exists, but here is a function will be compiled successfully:


    function retVal = MyFunction(inputs)
        netflag = MyAssembly.OpenMode.ReadOnly;
        % Some code...
    end

If you have faced similar problems in MATLAB and found a solution, please tell me what to do.

Thanks!

Regards, iroln

iroln
  • 1,116
  • 1
  • 16
  • 16

1 Answers1

2

I seem to find solutions to these problems. It's not very elegant, but it works.

The mcc compiler has the option "-a filename". This option enables you to add the specified files for CTF archive. You want to add all the files that defines the enumeration using .NET Assemblies:

Example for my case:

mcc -B csharedlib:MyLib MyFunction -a OpenMode

...or in general:

mcc -B csharedlib:MyLib MyFunction -a projectdir/*.m

I have automated this with a build-script. This is so far the only solution that works.

iroln
  • 1,116
  • 1
  • 16
  • 16