【发布时间】:2016-12-13 12:52:33
【问题描述】:
我尝试了两个星期来创建一个 DLL,我可以向其传递字符串并获取字符串。但还是没有成功。
我在 Dev-C++(TDM-GCC 4.9.2) 和 Visual Studio 社区 2015 上进行了尝试。我对此进行了很多搜索,并尝试了几乎所有找到的示例代码,但没有成功。
我必须将此 DLL 与 MetaTrader 终端 4 一起使用。
这是我使用的一个示例代码。这段代码编译成功,但是当我发送一个 string 给它时,来自 MT4,我得到一个访问冲突错误。
#ifndef MYLIB_HPP
#define MYLIB_HPP
#include <string>
#ifdef MYLIB_EXPORTS
#define MYLIB_API __declspec(dllimport)
#else
#define MYLIB_API __declspec(dllexport)
#endif
bool MYLIB_API test(const std::string& str);
#endif
bool MYLIB_API MyTest(const std::string& str)
{
return (str == "Hi There");
}
【问题讨论】:
-
能否也提供调用代码?
-
您的代码不包含对 mt4 的任何调用。那么问题出在哪里?
-
在我的 mt4 代码中我使用#import。
-
我从这里得到了帮助 stackoverflow.com/questions/31409006/how-to-return-a-string-of-unknown-size-from-dll-to-visual-basic 我已经使用 BSTR 完成了这项工作。
标签: c++ dll mql4 metatrader4 mt4