Calling MATLAB from a DLL

老子叫甜甜 提交于 2019-12-23 02:38:31

问题


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.

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).

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).

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?


回答1:


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.

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.

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#.



来源:https://stackoverflow.com/questions/37797403/calling-matlab-from-a-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!