从DLL调用MATLAB [英] Calling MATLAB from a DLL

查看:169
本文介绍了从DLL调用MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++编写的DLL,用于修改VISSIM(流量模拟器)中的参数.在此DLL中,我想调用MATLAB来发送数据,执行MATLAB函数并将数据返回到DLL.这一切都发生在IDE外部,因为VISSIM会根据需要调用DLL.

I have a DLL written in C++ that is used to modify parameters in VISSIM (traffic simulator). Within this DLL, I would like to call MATLAB to send data, perform MATLAB functions, and return data to the DLL. This all occurs outside of an IDE as VISSIM calls the DLL as necessary.

我有(1.)可以正常修改VISSIM参数的DLL,以及(2.)可以打开MATLAB引擎的.cpp程序(这两个程序当前是独立的-彼此独立).

I have (1.) a working DLL that properly modifies VISSIM parameters and (2.) a working .cpp program that opens the MATLAB Engine (these two programs are currently separate - independent of each other).

如何合并这两个程序,以便可以从现有DLL调用MATLAB引擎?无法简单地将.cpp MATLAB引擎程序复制粘贴到DLL中(我也修改了DLL项目属性,以包括必要的MATLAB库/目录/路径,就像在.cpp MATLAB引擎程序属性中所做的那样).

How can I combine these two programs so that I can call the MATLAB engine from my existing DLL? A simple copy-paste of the .cpp MATLAB engine program into the DLL did not work (I also modified the DLL project properties to include the necessary MATLAB libraries/directories/paths as is done in the .cpp MATLAB engine program properties).

注意:.cpp MATLAB引擎程序使用'stdafx.h'成功构建,但是复制到DLL然后构建时,出现致命错误C1083:无法打开包含文件:'stdafx.h'也许这是一个问题?

Note: The .cpp MATLAB engine program builds successfully with 'stdafx.h', but when copied to the DLL and then built, I receive fatal error C1083: Cannot open include file: 'stdafx.h' Perhaps this is an issue?

推荐答案

这是一个有趣的难题,因为您通常会运行MATLAB或某些其他COM接口语言来控制VISSIM,一旦仿真开始,VISSIM就会加载您的自定义DLL.在您的情况下,您希望DLL在VISSIM开始进行仿真后运行MATLAB.

This is an interesting dilemma as you would typically run MATLAB, or some other COM interface language, to control VISSIM which would load your custom DLL once a simulation begins. In your case you want the DLL to run MATLAB after VISSIM has started with a simulation.

我认为您最好的方法是使用第一种方法,即标准的通信方式,但要进行分散的数据交换.一种解决方案可能是让MATLAB启动VISSIM,当仿真开始时它将加载DLL. DLL可以将数据发送到数据库,XML文件,文本文件或其他数据容器. MATLAB将需要监视数据容器的更新并将其发送到VISSIM.这会有点慢,但应该可以.

I think your best approach is to use the first approach, the standard way of communication, but have a decentralized data exchange. One solution might be to have MATLAB start up VISSIM which will load the DLL when the simulation begins. The DLL could send data to a database, XML file, text file or other data container. MATLAB would need to monitor the data container for updates and send to VISSIM. This would be a bit slow but should work.

我有另一个想法,但是需要一些研究.如果您想讨论,请与我联系.在过去的七个月中,我一直在积极使用MATLAB,R,C ++和C#为VISSIM开发解决方案.

I have another idea but it requires a little research. Contact me if you would like to discuss. I have have been actively developing solutions for VISSIM for the last seven months using MATLAB, R, C++, and C#.

这篇关于从DLL调用MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆