Access Violation Error when run Matlab compiled function from C#
5 views (last 30 days)
Show older comments
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 Comment
Answers (0)
See Also
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!