calllib crashes MATLAB, no error given.

조회 수: 6 (최근 30일)
Sara van Hoogstraten
Sara van Hoogstraten 2019년 1월 21일
댓글: Sara van Hoogstraten 2019년 1월 21일
Hi,
I am trying to call a FORTRAN .dll in MATLAB (r2018b) using the function loadlibrary and calllib. With C++ I wrote the following .h file:
#ifndef _MYMODEL
#define _MYMODEL
#ifdef __cplusplus
extern "C" {
#endif // _cplusplus
// Functions and data types defined
void __stdcall MYFUN(char FILEA[], char FILEB[], int *IDTask, int *nErrorCode, int *ErrorCode, double *Props, double *Out1, double *Out2, double *Out3, double *Out4, double *Out5);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !_MYMODEL
In MATLAB, the library is loaded with loadlibrary (no errors). However, while calling the calllib function, MATLAB crashes and does not give an error. I saw the other thread on this (exchanging cdecl for stdcall in C++; https://nl.mathworks.com/matlabcentral/answers/18313-calllib-crashes-matlab-no-error-given), however, my 'mHeader' function does not contain cdecl (and stdcall only in the commented section).
Below, my MATLAB code is included:
%% Input to model
FILEA = 'PATH\FILEA.txt';
FILEB = 'PATH\FILEB.txt';
IDTask = 1;
%% Determine pointers
% input in .h file:
lpFILEA = libpointer('cstring', FILEA);
lpFILEB = libpointer('cstring', FILEB);
lpIDTask = libpointer('int32Ptr', IDTask);
lpnErrorCode = libpointer('int32Ptr');
lpErrorCode = libpointer('int32Ptr');
lpProps = libpointer('doublePtr');
lpOut1 = libpointer('doublePtr');
lpOut2 = libpointer('doublePtr');
lpOut3 = libpointer('doublePtr');
lpOut4 = libpointer('doublePtr');
lpOut5 = libpointer('doublePtr');
%% LoadLibrary
[notfound, warnings] = loadlibrary('MYMODEL.dll','MYMODEL.h' ,'mfilename', 'mHeader');
%% Call .dll
[~,~, ~, nErrorOut, ErrorCodeOut, PropsOut, Out1_, ~, ~, Out4_, Out5_] ...
= calllib('MYMODEL', 'MYFUN', lpFILEA, ...
lpFILEB, lpIDTask, lpnErrorCode, lpErrorCode, lpProps, lpOut1, ...
lpOut2, lpOut3, lpOut4, lpOut5);
Only the first three arguments as called in calllib are input, the remainder of the variables are output.
Thanks in advance for your help!
Kind regards,
Sara
  댓글 수: 7
Sara van Hoogstraten
Sara van Hoogstraten 2019년 1월 21일
I now downloaded both of the packages. However, in the .h file in Visual Studio, I cannot change the run-time library (as the properties window is empty). The same holds for the .dll file.
Sara van Hoogstraten
Sara van Hoogstraten 2019년 1월 21일
I just heard back from the developer: they used Microsoft Visual Studio 2015 and the Intel Fortran compiler for building the .dll.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by