- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这一定是一个基本问题,但我现在已经为这个问题苦苦挣扎了太久。我在 Google 上到处查看,发现了一些类似的问题和解决方案,但没有一个能解决我的具体问题。
我已经编写了一个非常基本的 C++ DLL。事实上,它几乎是 C 风格的,因为 DLL 只有一个带有函数的 main.cpp 代码文件,所以它甚至没有使用类。
然后我有两个头文件:
MqlUtils.h :
#ifndef MQLUTILS_H
#define MQLUTILS_H
struct MqlStr
{
int len;
char *string;
};
enum TradeOperation
{
OP_BUY = 0,
OP_SELL = 1,
OP_BUYLIMIT = 2,
OP_SELLLIMIT = 3,
OP_BUYSTOP = 4,
OP_SELLSTOP = 5
};
#endif
主.h :
#ifndef _DLL_H_
#define _DLL_H_
#include "MqlUtils.h"
#define MT4_EXPFUNC __declspec(dllexport)
#define export extern "C" __declspec( dllexport )
MT4_EXPFUNC int __stdcall GetOrdersDetailsNoSymbol(const int orderCount, const char * MasterLicense, const char * SlaveLicense, int orderTicket[], int op[],
double orderOpenPrice[], double orderStoploss[],
double orderTakeProfit[], double orderLots[], int orderDateTime[],
MqlStr * ordersymbol, MqlStr * ordercomments, int lotsCopyingMethod[], int returnedOrders[]);
#endif /* _DLL_H_ */
事实上,为了创建我的 DLL,我从其他人编写的现有代码开始,所以我的 DLL 的 .cpp 文件有一些晦涩的语法,我什至不确定它在做什么。以下是 .cpp 的摘录:
#include "main.h"
#define _UNICODE 1
#define UNICODE 1
#define WIN32_LEAN_AND_MEAN
// ...
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#if BUILDING_DLL
#define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
#define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
// ...
#ifdef __cplusplus
extern "C"
{
#endif
// ... function code
#ifdef __cplusplus
}
#endif
我没有包含 .cpp 文件中的所有内容,其中有 //...
还有其他内容,但这是我理解的基本内容,因此不应该是我的问题的根源......我很乐意根据需要发布更多内容。
我不是 __declspec 等晦涩关键字的专家,但可以成功导入 DLL,并且函数 GetOrdersDetailsNoSymbol 可以被某些程序使用,即 MetaTrader 4(这是的主要目标我的库)。
但现在我希望能够使用 C++ 程序测试我的库,所以我创建了一个空的控制台程序,将库项目添加到测试项目的引用中,并通过测试项目的引用链接了 .obj 和 .h 文件属性。
我目前在编译测试项目时得到这个:
Error 2 error LNK1120: 1 unresolved externals Z:\Codes\Debug\TestsCpp.exe TestsCpp
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl GetOrdersDetailsNoSymbol(int,char *,char *,int * const,int * const,double * const,double * const,double * const,double * const,int * const,struct MqlStr *,struct MqlStr *,int * const,int * const)" (__imp_?GetOrdersDetailsNoSymbol@@YAHHPAD0QAH1QAN2221PAUMqlStr@@311@Z) referenced in function "void __cdecl TestClient(void)" (?TestClient@@YAXXZ) Z:\Codes\TestsCpp\main.obj TestsCpp
哦,这是测试项目的 main.cpp :
#include "MqlUtils.h"
#include "main.h"
extern __declspec(dllimport) int GetOrdersDetailsNoSymbol(int orderCount, char * MasterLicense, char * SlaveLicense, int orderTicket[], int op[],
double orderOpenPrice[], double orderStoploss[],
double orderTakeProfit[], double orderLots[], int orderDateTime[],
MqlStr* ordersymbol, MqlStr* ordercomments, int lotsCopyingMethod[], int returnedOrders[]);
void TestClient()
{
char* Master = "7C83C4C2";
char* Slave = "3B7C22A";
int returnedOrderCount[1] = {0};
double aStoredOrderOpenPrice[4];
int aStoredOrderType[4];
int aStoredOrderTicket[4];
double aStoredOrderStopLoss[4];
double aStoredOrdeTakeProfit[4];
double aStoredOrderLots[4];
int aStoredOrderDateTime[4];
int aStoredLotsMethods[4];
MqlStr* aStoredOrderComment[4];
MqlStr* aStoredOrderSymbol[4];
for (int i = 0; i < 4; i++)
{
aStoredOrderOpenPrice[i]= -1;
aStoredOrderType[i]= -1;
aStoredOrderTicket[i]= -1;
aStoredOrderStopLoss[i]= -1;
aStoredOrdeTakeProfit[i]= -1;
aStoredOrderLots[i]= -1;
aStoredOrderDateTime[i]= -1;
aStoredLotsMethods[i]= -1;
aStoredOrderComment[i]->len = 56;
aStoredOrderComment[i]->string = "11111111111111111111111111111111111111111111111111111111";
aStoredOrderSymbol[i]->len = 56;
aStoredOrderSymbol[i]->string = "11111111111111111111111111111111111111111111111111111111";
}
GetOrdersDetailsNoSymbol(1, Master, Slave, aStoredOrderTicket, aStoredOrderType,
aStoredOrderOpenPrice, aStoredOrderStopLoss,
aStoredOrdeTakeProfit, aStoredOrderLots, aStoredOrderDateTime,
*aStoredOrderSymbol, *aStoredOrderComment, aStoredLotsMethods, returnedOrderCount);
}
int main(int argc, char **argv)
{
TestClient();
return 0;
}
如果有人能帮我解决这个问题,我将感激不尽。
感谢阅读!
最佳答案
您的两个 GetOrdersDetailsNoSymbol 声明不匹配。在您的头文件中,您使用 __stdcall 声明它,而在 main.cpp 中则没有。你应该只有一个声明。它可以根据需要使用#define 和#ifdef 来应用 dllimport 或 dllexport 关键字。
编辑:另外,去掉 extern "C"语句。然后使用 DLLIMPORT #define 来声明您的函数,并且在您的 DLL 构建中仅使用 #define BUILDING_DLL。
关于c++ - 在 C++ 中导入 DLL 和使用外部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9150886/
当我这样做时... import numpy as np ...我可以使用它但是... import pprint as pp ...不能,因为我需要这样做... from pprint import
我第一次尝试将 OpenCV 用于 Python 3。要安装,我只需在终端中输入“pip3 install opencv-python”。当我这样做时,我在 Finder(我在 Mac 上)中看到,在
如果有一个库我将使用至少两种方法,那么以下之间在性能或内存使用方面是否有任何差异? from X import method1, method2 和 import X 最佳答案 有区别,因为在 imp
我正在从 lodash 导入一些函数,我的同事告诉我,单独导入每个函数比将它们作为一个组导入更好。 当前方法: import {fn1, fn2, fn3} from 'lodash'; 首选方法:
之间有什么关系: import WSDL 中的元素 -和- import元素和在 XML Schema ...尤其是 location 之间的关系前者和 schemaLocation 的属性后者的属性
我在从 'theano.configdefaults' 导入 'local_bitwidth' 时遇到问题。并显示以下消息: ImportError
我注意到 React 可以这样导入: import * as React from 'react'; ...或者像这样: import React from 'react'; 第一个导入 react
对于当前的项目,我必须使用矩阵中提供的信息并对其进行数学计算,以及使用 ITK/VTK 函数来显示医疗信息/渲染。基本上我必须以(我猜)50/50 的方式同时使用 matlab 例程和 VTK/ITK
当我看到 pysqlite 的示例时,SQLite 库有两个用例。 from sqlite3 import dbapi2 as sqlite3 和 import sqlite3 为什么有两种方式支持s
我使用 Anaconda Python 发行版:Python 2.7 x64 和 Windows 7 SP1 x64 Ultimate。 当我import matplotlib.pyplot时,我得到
目录 【容器】镜像导出/导入 导出 导入 带标签 不带标签,后期修改 【仓库】镜像导出/导入
我正在寻找一种导入模块的方法,以便我可以从子文件夹 project/v0 和根文件夹 project 运行脚本。/p> 我在 python 3.6 中的文件结构(这就是没有初始化文件的原因) proj
我通常被告知以下是不好的做法。 from module import * 主要原因(或者有人告诉我)是,您可能会导入一些您不想要的东西,并且它可能会隐藏另一个模块中具有类似名称的函数或类。 但是,Py
我为 urllib (python3) 编写了一个小包装器。在if中导入模块是否正确且安全? if self.response_encoding == 'gzip': import gzip
我正在 pimcore 中创建一个新站点。有没有办法导出/导入 pimcore 站点的完整数据,以便我可以导出 xml/csv 格式的 pimcore 数据进行必要的更改,然后将其导入回来? 最佳答案
在 Node JS 中测试以下模块布局,看起来本地导出的定义总是在名称冲突的情况下替换外部导出的定义(参见 B.js 中的 f1)。 A.js export const f1 = 'A' B.js e
我在使用 VBA 代码时遇到了一些问题,该代码应该将 excel 数据导入我的 Access 数据库。当我运行代码时,我收到一个运行时错误“运行时错误 438 对象不支持此属性或方法”。来自我在其他论
我有一个名为 elements 的包,其中包含按钮、trifader、海报等内容。在 Button 类中,我正在执行 from elements import * 这执行正常,当我尝试 print(p
在我长期使用 python 的经验中,我遇到了一个非常奇怪的问题。 提前我想说我想知道为什么会发生这种情况 ,而不是如何更改我的代码或如何修复它,因为我也可以做到。 我正在使用 python2.7.3
我正在更新我的包。但是,我正在为依赖项/导入而苦苦挣扎。我使用了两个冲突的包 - ggplot2和 psych及其功能 alpha当然还有 alpha ggplot2 的对象不同于 alpha psy
我是一名优秀的程序员,十分优秀!