How can i use C++ DLL in Simulink?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to warn you that I am new to matlab and I hope for your calmness and kindness. <3
At work I was assigned the task: Connect .dll to matlab. This DLL came from another department, and I have no feedback with it.
So, what i have ?! DLL, Header files, config files for input values(xml) and description in docx format. In doxc i can check description for function, for example for ModelStart(). I dont have guide how to use this dll in docx!
Since my company's policy does not allow me to download, upload or send files to myself, I will attach below a piece of code from the main header file.
#pragma once
#include <windows.h>
#include <memory.h>
struct ModelFrame {
WORD chan;
WORD size;
ModelFrame(WORD c, WORD s)
{ Init(c,s); }
void Init(WORD c, WORD s){
chan = c;
size = s;
}
WORD Size()
{ return size; }
void Load(const void * src){
ModelFrame * m = (ModelFrame *) src;
chan = m->chan;
if (m->size < size){
if (m->size > 4)
memcpy((char *)this + 4, (char *)src+4, m->size - 4);
memset((char *)this + m->size, 0, size - m->size);
}
else if (size > 4)
memcpy ((char *)this + 4, (char *)src + 4, size - 4);
}
void Index(int idx)
{ chan = (chan&~3) + ((idx + 1)&3); }
int Index()
{ return ((chan&3) - 1)&3; }
};
typedef void (*PROGRESS_FUNC)(floar prg, char * msg);
typedef bool (*MODEL_MESSAGE)(const void * msg, DWORD length);
#ifdef MODEL_DLL
#define EXPORT_MODEL __declspec(dllexport)
#else
#define EXPORT_MODEL __declspec(dllimport)
void EXPORT_FFS ModelStart(double step, const char * dir, HWND window, MODEL_MESSAGE customRecv = 0, PROGRESS_FUNC pf = 0, const char * iface = 0, const chzr * addr = 0. int basePort = 32000);
#endif
If I understand correctly, the header file is written in C ++, which means that the DLL is also in C ++. I looked at a number of discussions on the forums about connecting dll to matlab and it all boiled down to using LoadLibrary() directly in the matlab console, or in a c mex function. Both of these methods gave me the same errors:

And i recieve big list of errors from dll like this two bellow:
Type 'LARGE_INTEGER' was not found. (winnt.h and ktmtypes.h)
Type 'REASON_CONTENT'/'DCB'/'PCONTEXT' was not found. (winbase.h)
And many other errors, that some types were not found from
winioct1.h , wtypes.h, rpcndr.h, wincrypt.h, prsht.h, winspool.h, objid1.h, oaid1.h, msxm1.h
and others...
So my main question is:
Can I connect this dll to matlab for further use or not? And if I can, then what should be my actions, in which direction to go, where to look for a solution to my problem? Or mb i should say to my boss, that this task is impossible?)
In addition:
>> mex -setup
MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation.
0 Kommentare
Antworten (1)
Yongjian Feng
am 12 Jul. 2021
Did you try to use 'addheader' of loadlibrary? The error seems to be related to header files.
https://www.mathworks.com/help/matlab/ref/loadlibrary.html
3 Kommentare
Yongjian Feng
am 12 Jul. 2021
C++ dll should work. The problem here seems to be the long dependency of header files.
It seems like the MEX approach is easier here.
Siehe auch
Kategorien
Mehr zu Use Prebuilt MATLAB Interface to C++ Library finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!