Access Violation Error when run Matlab compiled function from C#
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Compiler SDK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!