Access Violation Error when run Matlab compiled function from C#

10 vues (au cours des 30 derniers jours)
Martin Strelec
Martin Strelec le 2 Juil 2013
Commenté : Preetha Joy le 26 Sep 2017
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 commentaire
Preetha Joy
Preetha Joy le 26 Sep 2017
Are you able to solve this ? I am also facing the same issue

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by