How to tell if mclInitializeApplication has already been run in the current process

4 views (last 30 days)
I'm writing dlls that end up being plugins to another piece of code that I don't control. Each of my plugins calls another dll I created using MATLAB Compiler SDK. The first plugin that loads needs to intialize the environment using mclInitializeApplication, but the ones that load after that need to skip this step. The MATLAB Compiler SDK documentation makes it clear (and I've confirmed this) that this function should be called only once, total. But how do I avoid it? I don't necessarily know which one will initialize first, and I also have no way of knowing if some other third-party plugin that also uses MATLAB code may have already run this (or, even worse, whether they might be using a different version of the runtime libraries than I am, which I have no idea how to deal with...advice on that problem would be appreciated as well).
So, yeah, the subject line is the real question: How can I tell if it's already been run? Presumably mclInitializeApplication itself can't tell, or it would just be set up so that calling it redundantly has no effect, right? Doing it in a try-catch block doesn't seem to work, because rather than just throwing an exception, it screws up the whole environment in a way that doesn't seem possible to recover from.
Similarly, is there a way to find out if mclTerminateApplication has already been called?
I might just end up having to write different versions of each plugin, one with mclInitializeApplication commented out and one not, and just find the combination that works for any given installation. But this sounds really messy.
Surely if mclInitializeApplication can detect a problem well enough to return a "false" status flag at the end (which it does, so at least I can display meaningful error messages for my users), it should be able to detect this early enough to avoid corrupting the whole system?

Answers (1)

Varun Bhaskar
Varun Bhaskar on 26 Aug 2015
Hi,
You could use global flag variables to record whether mclInitializeApplication() and mclTerminateApplication() have been called. If not, then you can update these global flag variables to reflect that they have been called already.

Categories

Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!