loadlibrary and calllib inside a C mex routine
5 次查看(过去 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 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!