Mex files call DLL generated by .m file

1 回表示 (過去 30 日間)
Qun Wu
Qun Wu 2017 年 8 月 24 日
回答済み: Harsheel 2017 年 9 月 1 日
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

採用された回答

Harsheel
Harsheel 2017 年 9 月 1 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by