MEX -- unable to open external API

Hello *,
My question is related to a MATLAB/HyperMesh interaction by making use of the C/C++ interface provided with HyperMesh 11 -- referred to as Ext API. The problem is that I cannot open an interface. Here is a sample code which can reproduce the problem:
#include <mex.h>
#include "C:\Program Files\Altair\11.0\hm\include\hm_extapi.h"
#include "C:\Program Files\Altair\11.0\hm\include\hm_extapi_error.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Halli Hallo..\n");
int err_code;
HM_ExtAPI* hm_api = Open_HM_ExtAPI (&err_code);
mexPrintf("Err Code Number: %d\n", err_code);
if (err_code != ERR_XAPI_SUCCESS)
{
char buffer[512];
if (Open_HM_ExtAPI_GetErrorMessage (err_code, buffer, 512))
mexPrintf("MESSAGE: %s\n", buffer);
}
mexPrintf("Wie geths?\n");
mexPrintf("%s\n", hm_api);
Close_HM_ExtAPI(hm_api);
mexPrintf("Tschüss!\n");
return;
}
I copied the corresponding .dll file
hm_extapi.dll
to the MATLAB runtime directory path. Then I simply use this command to generate the MEX executable:
mex E:\WAP09Celsius1_Lucian\code\schnittstelle.cpp C:\Programme\Altair\11.0\hm\lib\win64\hm_extapi.lib
And by running the command:
schnittstelle
I get the following output:
Halli Hallo..
Err Code Number: 1
MESSAGE: HM DLL not found.
Wie geths?
(null)
Tschüss!
Any suggestion on how to solve it will be appreciated.
Cheers, Lucian. --

4 commentaires

Friedrich
Friedrich le 18 Avr 2013
Does it work when you call the same code from a plain C/C++ application? Doesn't seem to be a mex problem to me.
Update: If I run 'Dependency Walker' on 'schnittstelle.mexw64' I get the following files with a yellow question mark:
(1) LIBMEX.DLL
(2) WLANAPI.DLL
(3) MFPLAT.DLL
(4) MFREADWRITE.DLL
(5) MF.DLL
(6) IESHIMS.DLL
(7) MSVCR80.DLL
where files (2) to (6) are from:
c:\windows\system32\IEFRAME.DLL
but the remaning files (1) and (7), I have no idea why.
Friedrich
Friedrich le 18 Avr 2013
Delayload dependencies. A static analysis wont tell you whats wrong here. You need to do a runtime profile of the matlab.exe which calls the mex to get the correct information.
I runned the same code using Visual Studio 2005, which managed to create an API instance. Here is the output from my PowerShell of the generated .exe file:
Halli Hallo..
Error: initializing Tcl
tcl_library 'C:/Programme/Altair/11.0/hw/tcl/tcl8.5.6/win64/lib/tcl8.5' [C:/Programme/Altair/11.0/hw/tcl/tcl8.5.6/win64/lib/tcl8.5]
Err Code Number: 0
Wie geths?
ÿ║b
Tsch³ss!
So running the code from another application seems to be fine.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by