Access Violation Error when run Matlab compiled function from C#

5 ビュー (過去 30 日間)
Martin Strelec
Martin Strelec 2013 年 7 月 2 日
コメント済み: Preetha Joy 2017 年 9 月 26 日
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
  1 件のコメント
Preetha Joy
Preetha Joy 2017 年 9 月 26 日
Are you able to solve this ? I am also facing the same issue

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler SDK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by