COM generic components and mclInitializeApplication of MatlabRuntime

I have a set of generic COM components generated with the Deployment tool, and I would like to know whether I can include in these the functionality to (De)initialize the MatlabRuntime. I've seen some examples in the documentation about mclInitializeApplication but those apply to a Shared Library, which I know is a different deployment mean. Can you please refer me to some examples/information that clarifies how can I (De)Initialize the Matlab ruintime within a Generic COM component .dll? Thanks in advance

 Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 8 de Jun. de 2012
I'm assuming you use MATLAB Builder NE to generate the COM component? I haven't done this myself, but looking at the programming example here, it seems like the MCR (MATLAB Compiler Runtime) is automatically (un)initialized when the component is (un)initialized.

9 comentarios

Hi Kaustubha,
The example you mention on the link above -if I'm not mistaken- shows how to 'call a COM object in a Visual C++ program' . However, at the moment I have a number of COM dll files made with Matlab's deployment tool that are occassionally crashing during the call to Matlab routines. Our suspicion is that the Matlab runtime is not properly Unitialized last time we called Matlab code. Is there a way/tool that could help us to determine what could be the reason of the crash within the Matlab-generated .dll? Thanks in advance.
Orlando: Yes, the example is for calling a COM object generated using MATLAB Builder NE (which is one of the products that generates COM objects from MATLAB, the other being MATLAB Builder EX I think).
Regarding the crash - I wonder if it is actually an error in the deployed MATLAB code? I don't have experience with this, but do you have some kind of standard output available so that error messages can be displayed?
Hi Kaustubha,
I'm busy trying to reproduce the fault so that I can show you the corresponding output. In the mean time, I want to ask you whether using the (de) initialize ML functions can be combined with COM, i.e.
mclInitializeApplication();
//here goes my COM code
mclTerminateApplication();
Because I've seen the following output running a program with the above features -using the COM example from the documentation:
>> !matlab_com_example.exe (Visual C++ .NET 2003)
'Attempt to terminate while inhibit-shutdown is active
ML runtime successfully initialized .. The input values were 7.3 and 1946.
The output of feeding the inputs into the adddoubles method is 1953.3.
Failed to de-initialize ML runtime'
>> !matlab_com_example.exe (Visual C++ .NET 2005)
'ML runtime successfully initialized .. Attempt to terminate while inhibit-shutdown is active'
Thanks in advance,
Orlando.
Orlando: I've not done this before, but from the example in the documentation that I cited before, it looks like you should not need to call mclInitializeApplication and mclTerminateApplication at all. What happens if you remove both calls in your code?
HI Kaustubha,
The code without the mcl* functions does behave normally. What I've tried to find out is whether these functions could be combined with COM code. Currently my problem is that every now and then the code that uses the COM .dlls crashes and I suspect that it happens because a previous instance of the .dll stays in memory next time the same client code (in this case a test) runs.
With the mcl* functions I wanted test whether the previously loaded .dlls would be correctly removed before my test code runs again.
I that the mclInitializeApplication and mclTerminateApplication are already combined into the COM components initialize/terminate methods. They are automatically called when you initialize/terminate your component. You should probably use mclIsMCRInitialized if you just need to query if the MCR was terminated properly in the previous run.
Kaustubha, I'm afraid my compiler version does not provide such API function: I have r2007b :-( As of which version is this function available?
Oh no. Sorry to hear that. Not sure when it was introduced, but the documentation is here: http://www.mathworks.com/help/releases/R2011b/toolbox/compiler/f12-999353.html#br2jauc-39
I'm out of ideas at this point. Perhaps you could try contacting MathWorks Tech Support for your issue?
HI Kaustubha, I'm also running out of ideas. Thanks though for the support ;-) I'll see whether I contact Tech support.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by