Mex files call DLL generated by .m file

2 vues (au cours des 30 derniers jours)
Qun Wu
Qun Wu le 24 Août 2017
I have a myfile6.m function, it is a generic function with 1 input and 1 output. By following command:
mcc -W cpplib:YourLib -T link:lib myfile6.m
a bunch of files are generated:
YourLib.cpp
YourLib.def
YourLib.dll
YourLib.exp
YourLib.exports
YourLib.h
YourLib.lib
And then I try to link the .dll in my Mex file. I watched a lot of tutorial videos. One method is using LoadLibrary function, and a pointer which is to the address of the exported function in the DLL. The code looks like this:
#include <mex.h>
#include <windows.h>
typedef int(__stdcall *func_ptr)();
HINSTANCE hGetProcIDDLL = LoadLibrary(".dll file path") // double back slash
However, the example in videos are relatively simple. They have an explicit function in the source cpp file. Thus in this condition, we can directly use GetProcAddress function as following:
func_ptr funP = (fun_ptr)GetProcAddress(hGetProcIDDLL, "DLLfun");
When I open the generated source cpp file. It looks not easy since I am newie for matlab coding. I do not know how to put the second argument of the GetProcAddress function. I will upload the .cpp file and .h file. Could you please give me some suggestions? Or if the entire idea is wrong, please let me know. Thank you.
Qun

Réponse acceptée

Harsheel
Harsheel le 1 Sep 2017
You cannot load a MATLAB Compiler SDK generated shared library back into MATLAB. This is currently unsupported and is mentioned in the doc here.
You can, however, use the .dll from other applications. A complete example is documented here .
All the sample code from above link is available in the $matlabroot\extern\examples\compilersdk folder.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by