loadlibrary and calllib inside a C mex routine
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a vendor dll which I am trying to use with Matlab. I have a C code which calls this dll using GetProcAddress and then does lot of math with the data.
Now I know that I can use loadlibrary and calllib in Matlab to do the same. But then I would like to use the rest of the C code for fast simulation. However, I need to wrap this code in Matlab mex routine because I want to develop a Matlab GUI.
So my question is - how to write a C mex file which uses this C code? Or more specifically, should I retain the GetProcAddress in the mex code or should I replace those with calllib? Thanks rajn
0 件のコメント
回答 (2 件)
Kaustubha Govind
2011 年 8 月 18 日
I think it should be possible to continue using GetProcAddress in the MEX-function. However, remember that GetProcAddress belongs to the Windows-API, so you may have to jump through some hoops to get all the right compiler/linker options to work with the MEX command. See Custom Building MEX-Files for help.
2 件のコメント
Kaustubha Govind
2011 年 8 月 19 日
Yes, what you described is certainly possible. But I wouldn't necessary say that it is better than performing everything in C (like the code you already have). There is some overhead involved in marshaling data from the USB DLL to MATLAB, and then from MATLAB to the C-MEX file. However, if your math operations are complex enough to outweigh the data-marshaling overhead, this alternative approach may have comparable performance.
Philip Borghesani
2011 年 8 月 19 日
One possible transitional approach is to turn your c code into a dll/mex file that can be used with both loadlibrary and called directly as a mex file. See the example extern/examples/shrlib/yprime.c. It should be possible to use the USB dll from c and MATLAB with calllib at the same time allowing a gradual port of the code to MATLAB.
This approach will work will if your c code is well structured and you are proficient at c (or c++) coding.
You may find that some some of your c interfacing to the usb library can not be done as well using calllib because it is not as flexible as a c program. Working c interface code is often best left alone.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!