Access Violation Error when run Matlab compiled function from C#

Hi all,
I have a problem with calling Matlab function from C#. When I am calling Matlab function, the Access Violation Error (0x00000005) occurs.
Simple Matlab function was created:
function fcnHelloStrIn(str)
fprintf(sprintf('Hello world ... %s\n\n', (str)));
A dll library incorporating this function was created by Matlab compiler (4.17)
bool MW_CALL_CONV mlxFcnHelloStrIn(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
I tried to implement simple C# wrapper as follows (only relevant lines of code are included)
...
// ----- DLL import -----
[DllImport("HelloDll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
public static extern bool mlxFcnHelloStrIn([In] int nlhs, ref IntPtr outParams, [In] int nrhs, [In] IntPtr inParams);
...
MCR and Dll initialization function // OK
...
// ----- Main part -----
IntPtr outputPtr = IntPtr.Zero;
IntPtr stringPtr = IntPtr.Zero;
string helloString = "Hello world!";
stringPtr = mxCreateString(helloString);
bool result = mlxFcnHelloStrIn(0, ref outputPtr, 1, stringPtr);
....
When I call the function mlxFcnHelloStrIn then the access violation error (0xc0000005) arise. Does anybody know how to fix this issue?
Thanks in advance
Martin

답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기

질문:

2013년 7월 2일

댓글:

2017년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by