Simulink and DLLs
Simulink and DLLs
我需要将.EXE与simulink集成。我正在尝试在Simulink中创建一个C++DLL。该DLL稍后应合并到simulink中的S函数调用中。
信息流将是:
- Simulink执行S功能块
- 此块从C++DLL调用一个方法
- C++方法执行EXE,并返回一个结果
- 结果一直返回到simulink
ps:我没有EXE的源代码,它是一个黑盒。这就是为什么我要创建一个c++包装器,以便从simulink执行它。
到目前为止,C++DLL包装器无法工作。代码如下。
#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport)
#else
#define MATHFUNCSDLL_API __declspec(dllimport)
#endif
#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
extern "C" {
#endif
namespace MathFuncs
{
// This class is exported from the MathFuncsDll.dll
class MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);
};
}
#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
}
#endif
*.cpp
#include "stdafx.h"
#include <stdexcept>
#include "MathFuncsDll.h"
using namespace std;
namespace MathFuncs
{
double MyMathFuncs::Add(double a, double b)
{ return a + b; }
}
请注意,我正在使用(extern"c")命令来生成一个可以在Matlab c风格中使用的DLL。
当我尝试加载DLL:时
- 加载库('myDLL','myDLL.h')
- 库函数MathFuncsDll
"没有类lib.MathFuncsDll的方法或没有类lib.MathFuncsDll.">
所以,我的问题是:
- 我的dll项目出了什么问题
- 使用这种方法可以将exe与simulink集成吗
obs:类似的问题在这里
给出一些提示:
你想要一个2级的matlab函数,在这里解释:http://www.mathworks.de/de/help/simulink/sfg/writing-level-2-matlab-s-functions.html从msfuntmpl_basic.m
模板开始。
您可以完全跳过级别1的函数,它们的存在只是为了向后兼容。
我不是在解决dll错误,而是您从Simulink运行exe的原始问题。
-
为什么不像Daniel建议的那样使用
system
命令直接从MATALB代码运行exe? -
如果你写一个C++s函数,它的接口更容易实现,你可以从C++s函数调用你的exe。即,您将使用C++s函数作为Simulink和exe之间的接口,而不是DLL。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- 保证逻辑 AND 表达式中的函数调用
- python ctypes and C++ pointers
- C++ const char with .begin() and .end()
- Simulink and DLLs
- C++ STL and DLLs