Updated: I made a minimal example of the issue. Older versions of MATLAB (I was using 2015b) work fine with this code. MATLAB 2019b throws a NoActiveContextTypeError exception. It is possible to continue past the exception, but I'm not sure that this is safe.
I've attached a visual studio solution that points to my matlab installation libraries. You might need to change the path in project settings -- I have it pointing at D:\MATLAB\R2019b in three places:
- VC++ Directories / Include Directories (D:\MATLAB\R2019b\extern\include)
- C/C++ General / Additional Include Directories (D:\MATLAB\R2019b\extern\include)
- Linker / General / Additional Library Directories (D:\MATLAB\R2019b\extern\lib\win64\microsoft)
- Also call "matlab /regserver" in MATLAB\R2019b\bin\win64 if you need to
As discussed below, adding an initial field name instead of NULL doesn't change the behavior.
What is the reason for the exception and is this code safe?
-------------- Original Question --------------
I have C++ code that starts a matlab session using engOpenSingleUse(). It builds data structures using mxCreateStructMatrix() and sends them over to Matlab using engPutVariable(). It executes some user code via engEvalString(), and fetches the results with engGetVariable(). This has all been working fine for a few years. Recently I was unable to get my code to work with MATLAB 2019b. It works fine with 2015b. When linking with 2019b stuff I get the following cryptic error on mxCreateStructMatrix():
engOpenSingleUse() seems to work. Was mxCreateStructMatrix depricated or were breaking changes made to the interface? I am confused about the difference between the C Matrix API and the newer C++ API that was released around 2017b.
I am looking for a solution we can deploy for calling MATLAB code and sending data from a C++ application that is compatible with a wide range of MATLAB versions.