Matlab crashes when calling dll

We have created a dll for an application if we try to call that dll(run loader.m file)suddenly matlab crashes..Need suggestion in this regard

2 件のコメント

Kaustubha Govind
Kaustubha Govind 2013 年 5 月 31 日
You probably also want to clarify that you are calling into a DLL generated by Simulink Coder, and paste the prototypes of the exports from the library from the header file.
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
編集済み: vinothkannan K 2013 年 6 月 5 日
Hi Kaustubha Govind, We generated header file from dll, even though matlab crashes, when running dll.
This is the command we used for generation of header file
loadlibrary('TOLI_win32','TOLI.h','mfilename','TOLI_header');

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

回答 (1 件)

Craig Cowled
Craig Cowled 2013 年 5 月 31 日

0 投票

Try using 'loadlibrary'.

12 件のコメント

vinothkannan K
vinothkannan K 2013 年 5 月 31 日
we used loadlibrary command to load the dll..
Below is the code:
libfile='TOLI_win32';
loadlibrary(libfile,@TOLI_header);
libfunctionsview TOLI_win32;
a=uint16(1);
calllib('TOLI_win32', 'TOLI_initialize',a);
while (1)
calllib('TOLI_win32', 'TOLI_step');
pause(1);
end
unloadlibrary('TOLI_win32')
Here the dll is "TOLI_win32" 'a' is the variable
Friedrich
Friedrich 2013 年 6 月 5 日
Which lines raises the crash? Does your DLL work in a plain C/C++ application? The functionsignature of the functions you call seem pretty simple so I would guess its a BUG in the DLL.
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
libfile='TOLI_win32';
loadlibrary(libfile,@TOLI_header);
libfunctionsview TOLI_win32;
firstTime = uint8(1);
calllib('TOLI_win32', 'TOLI_initialize',firstTime);
while (1)
calllib('TOLI_win32', 'TOLI_step');
pause(1);
end
unloadlibrary('TOLI_win32')
This is the M file we are using to call dll, The model is working fine, while running dll its raising error at 'TOLI_step' function....
Friedrich
Friedrich 2013 年 6 月 5 日
Write some C code and test it outside of ML. I guess it crashes there too.
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
Hi its crashing because of ResumeThread function, this function is available from windows. Any idea about it?
Friedrich
Friedrich 2013 年 6 月 5 日
I would need to see the actual code. For now its to vague to tell anything.
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
Its crashing at this lines
if ( ResumeThread( ArrayThreadHandles[i].ThreadHandle ) != - 1)
{
// set the state of this thread to active
ArrayThreadHandles[i].ThreadActive = 1;
}
Friedrich
Friedrich 2013 年 6 月 5 日
Is i in valid range? Is the ThreadHandle still valid?
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
Yes, Because it is working while running model.,
Friedrich
Friedrich 2013 年 6 月 5 日
編集済み: Friedrich 2013 年 6 月 5 日
One would assume that the generated code behaves like the model, however it could be a bug in the code generation or maybe a design problem of your model which works in MATLAB/Simulink becauses MATLAB takes care of out of bounds accesses whereas C doesnt.
If everything is valid, then it wouldn't crash.
Compile that DLL in debug mode and attach a Debugger to it at runtime to step thorugh the code and to be able to inspect the values at runtime.
vinothkannan K
vinothkannan K 2013 年 6 月 5 日
Ok i will check in debug mode, Thanks for your support.,
vinothkannan K
vinothkannan K 2013 年 6 月 6 日
編集済み: vinothkannan K 2013 年 6 月 6 日
Hi Friedrich
1)Can you please explain about compiling dll in debug mode?
2) What are all the configuration parameter settings for debug mode dll compilation?
3) How to attach debugger to it at runtime?
Thanks in advance

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

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

質問済み:

2013 年 5 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by