MCR issue at initialization

22 views (last 30 days)
Bruno on 15 Jan 2013
Answered: Tao Cui on 15 Dec 2017
I'm facing a weird issue. My Application can use MATLAB code embedded in plugin DLL. I've generated C++ shared dll using MATLAB Compiler 4.18. Two months ago everything went fine, the Matlab generated dll was used by another dll which is a wrapper for my application written in C++.
Now I want to build another MATLAB dll and wrap it the same way, but the libInitialize() call fails.
Here is part of the code doing initializations :
// in the wrapper DLL a constructor is initializing the MATLAB part
if (mclInitializeApplication(NULL, 0))
if (myLibInitialize())
When debugging i've found that the crash is here:
bool myLibInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler)
int bResult = 0;
if (_mcr_inst != NULL)
return true;
if (!mclmcrInitialize())
return false;
if (!GetModuleFileName(GetModuleHandle("myLib"), path_to_dll, _MAX_PATH))
return false;
mclCtfStream ctfStream =
if (ctfStream) {
bResult = mclInitializeComponentInstanceEmbedded( &_mcr_inst,
} else {
bResult = 0;
if (!bResult)
return false;
return true;
Crash in mclInitializeComponentInstanceEmbedded which i can't debug trace since it's part of MCR. I've noticed, though, that _mcr_inst pointer is always NULL. Is it the source of the issue?
I've lost my mind since the same code worked perfectly two months ago on my PC. I changed nothing, MATLAB is still 2012b, Matlab Compiler 4.18 and MCR installed on my Windows 7 64bit.
I guess the issue is linked to CTF acces problem. I tried to build my Matlab C++ DLL with no ctf embedded, same result.
I tried with simple matlab code in one .m file, same result.
Any suggestions appreciated.

Answers (1)

Tao Cui
Tao Cui on 15 Dec 2017
not sure if your problem was solved since this is an old post. I have encountered same issue and this post solved my problem:
Simple solution: do not include Matlab generated CPP files into your project, just use the header and the lib.

Community Treasure Hunt

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

Start Hunting!